summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-06-15 16:33:09 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-06-15 22:23:02 +0200
commit522ba1cd98ac67482061448c3a7528e68a720f0d (patch)
tree527560bfa89b66683c1118d132c8270b42812777 /resources
parent889dc47ceba9cf5cbd6e61a9222a5e54cd562332 (diff)
Fix order of GetTerms
Preserve the order from front matter, which would be behaviour when doing this manually (before GetTerms). Fixes #7213
Diffstat (limited to 'resources')
-rw-r--r--resources/page/pages_sort.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/resources/page/pages_sort.go b/resources/page/pages_sort.go
index b0e7f8e32..85817ffda 100644
--- a/resources/page/pages_sort.go
+++ b/resources/page/pages_sort.go
@@ -16,6 +16,8 @@ package page
import (
"sort"
+ "github.com/gohugoio/hugo/common/collections"
+
"github.com/gohugoio/hugo/resources/resource"
"github.com/gohugoio/hugo/compare"
@@ -37,6 +39,19 @@ type pageSorter struct {
// pageBy is a closure used in the Sort.Less method.
type pageBy func(p1, p2 Page) bool
+func getOrdinals(p1, p2 Page) (int, int) {
+ p1o, ok1 := p1.(collections.Order)
+ if !ok1 {
+ return -1, -1
+ }
+ p2o, ok2 := p2.(collections.Order)
+ if !ok2 {
+ return -1, -1
+ }
+
+ return p1o.Ordinal(), p2o.Ordinal()
+}
+
// Sort stable sorts the pages given the receiver's sort order.
func (by pageBy) Sort(pages Pages) {
ps := &pageSorter{
@@ -49,8 +64,12 @@ func (by pageBy) Sort(pages Pages) {
var (
// DefaultPageSort is the default sort func for pages in Hugo:
- // Order by Weight, Date, LinkTitle and then full file path.
+ // Order by Ordinal, Weight, Date, LinkTitle and then full file path.
DefaultPageSort = func(p1, p2 Page) bool {
+ o1, o2 := getOrdinals(p1, p2)
+ if o1 != o2 && o1 != -1 && o2 != -1 {
+ return o1 < o2
+ }
if p1.Weight() == p2.Weight() {
if p1.Date().Unix() == p2.Date().Unix() {
c := compare.Strings(p1.LinkTitle(), p2.LinkTitle())