ref: 2e2e34a9350edec0220462aa3d47ecc9d428a0fb
parent: 2eed35c826e5de6aae432b36969a28c2ae3e0f02
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Sep 21 10:23:00 EDT 2018
hugolib: Deprecate Pages.Sort In favour of ByWeight.
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -525,10 +525,10 @@
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 @@
allPages = append(allPages, s.Pages...)
}
- allPages.Sort()
+ allPages.sort()
for _, s := range h.Sites {
s.AllPages = allPages
--- 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 @@
// 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)
}
--- a/hugolib/pageSort_test.go
+++ b/hugolib/pageSort_test.go
@@ -35,24 +35,24 @@
// 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())
--- a/hugolib/page_bundler.go
+++ b/hugolib/page_bundler.go
@@ -192,7 +192,7 @@
return err
}
- s.site.rawAllPages.Sort()
+ s.site.rawAllPages.sort()
return nil
--- a/hugolib/pages_language_merge.go
+++ b/hugolib/pages_language_merge.go
@@ -42,7 +42,7 @@
}
}
- pages.Sort()
+ pages.sort()
}
out, _ := spc.getP("pages.MergeByLanguage", merge, p1, p2)
--- a/hugolib/site_sections.go
+++ b/hugolib/site_sections.go
@@ -326,7 +326,7 @@
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 (p *Page) setPagePages(pages Pages) {
- pages.Sort()
+ pages.sort()
p.Pages = pages
p.data = make(map[string]interface{})
p.data["Pages"] = pages