diff options
author | Tatsushi Demachi <tdemachi@gmail.com> | 2014-10-18 00:10:19 +0900 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-11-01 22:41:04 -0400 |
commit | 5e28606b84ef230914d0e63aebe3925364ee3966 (patch) | |
tree | 9c88a8d4b1c62178540645300a73e5c754a54b7c /hugolib/pageSort.go | |
parent | d013edb7f838b739db72530e06eb47721baec7b8 (diff) |
Add sort and grouping functions for publish date and param of Page
`GroupBy` is modified to allow it to receive a method name argument for
example `Type` as its first argument. It is only allowed to call with
a method which takes no arguments and returns a result or a pair of
a result and an error.
The functions discussed at #443 are also added
- `ByPublishDate`: Order contents by `PublishDate` front matter variable
- `GroupByPublishDate(format, order)`: Group contents by `PublishDate`
front matter variable formatted in string like `GroupByDate`
- `GroupByParam(key, order)`: Group contents by `Param` front matter
variable specified by `key` argument
- `GroupByParamDate(key, format, order)`: Group contents by `Param`
front matter variable specified by `key` argument and formatted in
string like `GroupByDate`. It's effective against `time.Time` type
front matter variable
Diffstat (limited to 'hugolib/pageSort.go')
-rw-r--r-- | hugolib/pageSort.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/hugolib/pageSort.go b/hugolib/pageSort.go index c621740b2..dbbdc4c20 100644 --- a/hugolib/pageSort.go +++ b/hugolib/pageSort.go @@ -96,6 +96,15 @@ func (p Pages) ByDate() Pages { return p } +func (p Pages) ByPublishDate() Pages { + pubDate := func(p1, p2 *Page) bool { + return p1.PublishDate.Unix() < p2.PublishDate.Unix() + } + + PageBy(pubDate).Sort(p) + return p +} + func (p Pages) ByLength() Pages { length := func(p1, p2 *Page) bool { return len(p1.Content) < len(p2.Content) |