aboutsummaryrefslogtreecommitdiff
path: root/page/pagelist.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
commit268fcf7e6b671d4959a12111d5abf553bf0a201b (patch)
tree6f5c46c9a765478eaae78d66f4b9aefc953bbd1a /page/pagelist.go
parentd36b6a55c8fa4400cd39de717443e110e990a8a3 (diff)
downloadgo-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.gz
go-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.xz
Redis caching. Linter config and cleanup.
Diffstat (limited to 'page/pagelist.go')
-rw-r--r--page/pagelist.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/page/pagelist.go b/page/pagelist.go
index f2140f9..298acf9 100644
--- a/page/pagelist.go
+++ b/page/pagelist.go
@@ -5,15 +5,16 @@ import (
)
// PageList is a slice of pages, providing a couple of methods to sort
-// by the date, or date reversed
+// by the date, or date reversed.
type PageList []*Page
// RemoveDateless returns two PageLists, the first with valid dates,
// and the second without. This is useful if you need a PageList which
-// will run SortDate and SortDateReverse without issue
+// will run SortDate and SortDateReverse without issue.
func (p PageList) RemoveDateless() (PageList, PageList) {
with := PageList{}
without := PageList{}
+
for _, p := range p {
if p.Date != nil {
with = append(with, p)
@@ -21,19 +22,26 @@ func (p PageList) RemoveDateless() (PageList, PageList) {
without = append(without, p)
}
}
+
return with, without
}
+// SortDate returns the pagelist sorted by date, may panic if pages do
+// not all have dates.
func (p PageList) SortDate() PageList {
sort.Slice(p, func(i, j int) bool {
return p[i].Time().After(p[j].Time())
})
+
return p
}
+// SortDateReverse returns the pagelist sorted by date in reverse, may panic if
+// pages do not all have dates.
func (p PageList) SortDateReverse() PageList {
sort.Slice(p, func(i, j int) bool {
return p[i].Time().Before(p[j].Time())
})
+
return p
}