URI: 
       Add ByLastmod page sort - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 10af906371bedb643f67d89ec370a1236c6504fd
   DIR parent fbca53ac325324db104df5de86add3fa0baf3488
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Fri, 22 Apr 2016 20:43:00 +0200
       
       Add ByLastmod page sort
       
       Diffstat:
         M hugolib/pageSort.go                 |      18 ++++++++++++++++++
         M hugolib/pageSort_test.go            |      11 ++++++++---
       
       2 files changed, 26 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go
       @@ -158,6 +158,24 @@ func (p Pages) ByPublishDate() Pages {
                return pages
        }
        
       +// ByLastmod sorts the Pages by the last modification date and returns a copy.
       +//
       +// Adjacent invocactions on the same receiver will return a cached result.
       +//
       +// This may safely be executed  in parallel.
       +func (p Pages) ByLastmod() Pages {
       +
       +        key := "pageSort.ByLastmod"
       +
       +        date := func(p1, p2 *Page) bool {
       +                return p1.Lastmod.Unix() < p2.Lastmod.Unix()
       +        }
       +
       +        pages, _ := spc.get(key, p, pageBy(date).Sort)
       +
       +        return pages
       +}
       +
        // ByLength sorts the Pages by length and returns a copy.
        //
        // Adjacent invocactions on the same receiver will return a cached result.
   DIR diff --git a/hugolib/pageSort_test.go b/hugolib/pageSort_test.go
       @@ -15,12 +15,13 @@ package hugolib
        
        import (
                "fmt"
       -        "github.com/spf13/hugo/source"
       -        "github.com/stretchr/testify/assert"
                "html/template"
                "path/filepath"
                "testing"
                "time"
       +
       +        "github.com/spf13/hugo/source"
       +        "github.com/stretchr/testify/assert"
        )
        
        func TestDefaultSort(t *testing.T) {
       @@ -67,6 +68,7 @@ func TestSortByN(t *testing.T) {
                        {(Pages).ByLinkTitle, func(p Pages) bool { return p[0].LinkTitle() == "abl" }},
                        {(Pages).ByDate, func(p Pages) bool { return p[0].Date == d3 }},
                        {(Pages).ByPublishDate, func(p Pages) bool { return p[0].PublishDate == d3 }},
       +                {(Pages).ByLastmod, func(p Pages) bool { return p[1].Lastmod == d2 }},
                        {(Pages).ByLength, func(p Pages) bool { return p[0].Content == "b_content" }},
                } {
                        setSortVals([3]time.Time{d1, d2, d3}, [3]string{"b", "ab", "cde"}, [3]int{3, 2, 1}, p)
       @@ -114,6 +116,7 @@ func BenchmarkSortByWeightAndReverse(b *testing.B) {
        func setSortVals(dates [3]time.Time, titles [3]string, weights [3]int, pages Pages) {
                for i := range dates {
                        pages[i].Date = dates[i]
       +                pages[i].Lastmod = dates[i]
                        pages[i].Weight = weights[i]
                        pages[i].Title = titles[i]
                        // make sure we compare apples and ... apples ...
       @@ -121,7 +124,9 @@ func setSortVals(dates [3]time.Time, titles [3]string, weights [3]int, pages Pag
                        pages[len(dates)-1-i].PublishDate = dates[i]
                        pages[len(dates)-1-i].Content = template.HTML(titles[i] + "_content")
                }
       -
       +        lastLastMod := pages[2].Lastmod
       +        pages[2].Lastmod = pages[1].Lastmod
       +        pages[1].Lastmod = lastLastMod
        }
        
        func createSortTestPages(num int) Pages {