package page import ( "sort" ) // PageList is a slice of pages, providing a couple of methods to sort // 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 func (p PageList) RemoveDateless() (PageList, PageList) { with := PageList{} without := PageList{} for _, p := range p { if p.Date != nil { with = append(with, p) } else { without = append(without, p) } } return with, without } func (p PageList) SortDate() PageList { sort.Slice(p, func(i, j int) bool { return p[i].Time().After(p[j].Time()) }) return p } func (p PageList) SortDateReverse() PageList { sort.Slice(p, func(i, j int) bool { return p[i].Time().Before(p[j].Time()) }) return p }