mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-22 01:12:48 +00:00
parent
57c347e4cc
commit
98ee8c3f7b
1 changed files with 18 additions and 0 deletions
|
@ -21,6 +21,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PageGroup represents a group of pages, grouped by the key.
|
||||||
|
// The key is typically a year or similar.
|
||||||
type PageGroup struct {
|
type PageGroup struct {
|
||||||
Key interface{}
|
Key interface{}
|
||||||
Pages Pages
|
Pages Pages
|
||||||
|
@ -63,8 +65,11 @@ func sortKeys(v []reflect.Value, order string) []reflect.Value {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PagesGroup represents a list of page groups.
|
||||||
|
// This is what you get when doing page grouping in the templates.
|
||||||
type PagesGroup []PageGroup
|
type PagesGroup []PageGroup
|
||||||
|
|
||||||
|
// Reverse reverses the order of this list of page groups.
|
||||||
func (p PagesGroup) Reverse() PagesGroup {
|
func (p PagesGroup) Reverse() PagesGroup {
|
||||||
for i, j := 0, len(p)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(p)-1; i < j; i, j = i+1, j-1 {
|
||||||
p[i], p[j] = p[j], p[i]
|
p[i], p[j] = p[j], p[i]
|
||||||
|
@ -78,6 +83,8 @@ var (
|
||||||
pagePtrType = reflect.TypeOf((*Page)(nil))
|
pagePtrType = reflect.TypeOf((*Page)(nil))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GroupBy groups by the value in the given field or method name and with the given order.
|
||||||
|
// Valid values for order is asc, desc, rev and reverse.
|
||||||
func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
|
func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
|
||||||
if len(p) < 1 {
|
if len(p) < 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -143,6 +150,8 @@ func (p Pages) GroupBy(key string, order ...string) (PagesGroup, error) {
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupByParam groups by the given page parameter key's value and with the given order.
|
||||||
|
// Valid values for order is asc, desc, rev and reverse.
|
||||||
func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) {
|
func (p Pages) GroupByParam(key string, order ...string) (PagesGroup, error) {
|
||||||
if len(p) < 1 {
|
if len(p) < 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -218,6 +227,9 @@ func (p Pages) groupByDateField(sorter func(p Pages) Pages, formatter func(p *Pa
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupByDate groups by the given page's Date value in the given format and with the given order.
|
||||||
|
// Valid values for order is asc, desc, rev and reverse.
|
||||||
|
// For valid format strings, see https://golang.org/pkg/time/#Time.Format
|
||||||
func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error) {
|
func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error) {
|
||||||
sorter := func(p Pages) Pages {
|
sorter := func(p Pages) Pages {
|
||||||
return p.ByDate()
|
return p.ByDate()
|
||||||
|
@ -228,6 +240,9 @@ func (p Pages) GroupByDate(format string, order ...string) (PagesGroup, error) {
|
||||||
return p.groupByDateField(sorter, formatter, order...)
|
return p.groupByDateField(sorter, formatter, order...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupByPublishDate groups by the given page's PublishDate value in the given format and with the given order.
|
||||||
|
// Valid values for order is asc, desc, rev and reverse.
|
||||||
|
// For valid format strings, see https://golang.org/pkg/time/#Time.Format
|
||||||
func (p Pages) GroupByPublishDate(format string, order ...string) (PagesGroup, error) {
|
func (p Pages) GroupByPublishDate(format string, order ...string) (PagesGroup, error) {
|
||||||
sorter := func(p Pages) Pages {
|
sorter := func(p Pages) Pages {
|
||||||
return p.ByPublishDate()
|
return p.ByPublishDate()
|
||||||
|
@ -238,6 +253,9 @@ func (p Pages) GroupByPublishDate(format string, order ...string) (PagesGroup, e
|
||||||
return p.groupByDateField(sorter, formatter, order...)
|
return p.groupByDateField(sorter, formatter, order...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupByParamDate groups by a date set as a param on the page in the given format and with the given order.
|
||||||
|
// Valid values for order is asc, desc, rev and reverse.
|
||||||
|
// For valid format strings, see https://golang.org/pkg/time/#Time.Format
|
||||||
func (p Pages) GroupByParamDate(key string, format string, order ...string) (PagesGroup, error) {
|
func (p Pages) GroupByParamDate(key string, format string, order ...string) (PagesGroup, error) {
|
||||||
sorter := func(p Pages) Pages {
|
sorter := func(p Pages) Pages {
|
||||||
var r Pages
|
var r Pages
|
||||||
|
|
Loading…
Reference in a new issue