diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-09-21 14:23:00 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-09-21 14:23:00 +0200 |
commit | 2e2e34a9350edec0220462aa3d47ecc9d428a0fb (patch) | |
tree | d72c0e66d373be604342aff2ccc0100ca6fb8bee | |
parent | 2eed35c826e5de6aae432b36969a28c2ae3e0f02 (diff) | |
download | hugo-2e2e34a9350edec0220462aa3d47ecc9d428a0fb.tar.gz hugo-2e2e34a9350edec0220462aa3d47ecc9d428a0fb.zip |
hugolib: Deprecate Pages.Sort
In favour of ByWeight.
-rw-r--r-- | hugolib/hugo_sites.go | 6 | ||||
-rw-r--r-- | hugolib/pageSort.go | 10 | ||||
-rw-r--r-- | hugolib/pageSort_test.go | 8 | ||||
-rw-r--r-- | hugolib/page_bundler.go | 2 | ||||
-rw-r--r-- | hugolib/pages_language_merge.go | 2 | ||||
-rw-r--r-- | hugolib/site_sections.go | 4 |
6 files changed, 20 insertions, 12 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index e5358ec19..88715a86e 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -525,10 +525,10 @@ func (h *HugoSites) createMissingPages() error { first.AllPages = append(first.AllPages, newPages...) - first.AllPages.Sort() + first.AllPages.sort() for _, s := range h.Sites { - s.Pages.Sort() + s.Pages.sort() } for i := 1; i < len(h.Sites); i++ { @@ -574,7 +574,7 @@ func (h *HugoSites) setupTranslations() { allPages = append(allPages, s.Pages...) } - allPages.Sort() + allPages.sort() for _, s := range h.Sites { s.AllPages = allPages diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go index dfd17b2b0..92b767ffe 100644 --- a/hugolib/pageSort.go +++ b/hugolib/pageSort.go @@ -1,4 +1,4 @@ -// Copyright 2015 The Hugo Authors. All rights reserved. +// Copyright 2018 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ package hugolib import ( + "github.com/gohugoio/hugo/helpers" + "sort" "github.com/spf13/cast" @@ -98,6 +100,12 @@ func (ps *pageSorter) Less(i, j int) bool { return ps.by(ps.pages[i], ps.pages[j // Sort sorts the pages by the default sort order defined: // Order by Weight, Date, LinkTitle and then full file path. func (p Pages) Sort() { + // Remove in Hugo 0.51 + helpers.Deprecated("Pages", "Sort", "Use .ByWeight", false) + p.sort() +} + +func (p Pages) sort() { pageBy(defaultPageSort).Sort(p) } diff --git a/hugolib/pageSort_test.go b/hugolib/pageSort_test.go index f842ecd78..bc4be1cb0 100644 --- a/hugolib/pageSort_test.go +++ b/hugolib/pageSort_test.go @@ -35,24 +35,24 @@ func TestDefaultSort(t *testing.T) { // first by weight setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "c", "d"}, [4]int{4, 3, 2, 1}, p) - p.Sort() + p.sort() assert.Equal(t, 1, p[0].Weight) // Consider zero weight, issue #2673 setSortVals([4]time.Time{d1, d2, d3, d4}, [4]string{"b", "a", "d", "c"}, [4]int{0, 0, 0, 1}, p) - p.Sort() + p.sort() assert.Equal(t, 1, p[0].Weight) // next by date setSortVals([4]time.Time{d3, d4, d1, d2}, [4]string{"a", "b", "c", "d"}, [4]int{1, 1, 1, 1}, p) - p.Sort() + p.sort() assert.Equal(t, d1, p[0].Date) // finally by link title setSortVals([4]time.Time{d3, d3, d3, d3}, [4]string{"b", "c", "a", "d"}, [4]int{1, 1, 1, 1}, p) - p.Sort() + p.sort() assert.Equal(t, "al", p[0].LinkTitle()) assert.Equal(t, "bl", p[1].LinkTitle()) assert.Equal(t, "cl", p[2].LinkTitle()) diff --git a/hugolib/page_bundler.go b/hugolib/page_bundler.go index fc135f6b7..6870dc152 100644 --- a/hugolib/page_bundler.go +++ b/hugolib/page_bundler.go @@ -192,7 +192,7 @@ func (s *siteContentProcessor) process(ctx context.Context) error { return err } - s.site.rawAllPages.Sort() + s.site.rawAllPages.sort() return nil diff --git a/hugolib/pages_language_merge.go b/hugolib/pages_language_merge.go index ef87ac9cb..8bbae9a12 100644 --- a/hugolib/pages_language_merge.go +++ b/hugolib/pages_language_merge.go @@ -42,7 +42,7 @@ func (p1 Pages) MergeByLanguage(p2 Pages) Pages { } } - pages.Sort() + pages.sort() } out, _ := spc.getP("pages.MergeByLanguage", merge, p1, p2) diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go index 15b96e1a7..d27b31614 100644 --- a/hugolib/site_sections.go +++ b/hugolib/site_sections.go @@ -326,7 +326,7 @@ func (s *Site) assembleSections() Pages { for _, sect := range sectionPages { if sect.parent != nil { - sect.parent.subSections.Sort() + sect.parent.subSections.sort() } for i, p := range sect.Pages { @@ -356,7 +356,7 @@ func (s *Site) assembleSections() Pages { } func (p *Page) setPagePages(pages Pages) { - pages.Sort() + pages.sort() p.Pages = pages p.data = make(map[string]interface{}) p.data["Pages"] = pages |