hugolib: Deprecate Pages.Sort - hugo - [fork] hugo port for 9front
 (HTM) git clone git@git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2e2e34a9350edec0220462aa3d47ecc9d428a0fb
 (DIR) parent 2eed35c826e5de6aae432b36969a28c2ae3e0f02
 (HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Fri, 21 Sep 2018 14:23:00 +0200
       
       hugolib: Deprecate Pages.Sort
       
       In favour of ByWeight.
       
       Diffstat:
         M hugolib/hugo_sites.go               |       6 +++---
         M hugolib/pageSort.go                 |      10 +++++++++-
         M hugolib/pageSort_test.go            |       8 ++++----
         M hugolib/page_bundler.go             |       2 +-
         M hugolib/pages_language_merge.go     |       2 +-
         M hugolib/site_sections.go            |       4 ++--
       
       6 files changed, 20 insertions(+), 12 deletions(-)
       ---
 (DIR) diff --git 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
 (DIR) diff --git 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)
        }
        
 (DIR) diff --git 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())
 (DIR) diff --git 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
        
 (DIR) diff --git 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)
 (DIR) diff --git 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