mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Adding Prev/Next functionality to all lists of pages (sections, taxonomies, etc)
This commit is contained in:
@@ -160,6 +160,30 @@ func (wp WeightedPages) Pages() Pages {
|
||||
return pages
|
||||
}
|
||||
|
||||
func (wp WeightedPages) Prev(cur *Page) *Page {
|
||||
for x, c := range wp {
|
||||
if c.Page.UniqueId() == cur.UniqueId() {
|
||||
if x == 0 {
|
||||
return wp[len(wp)-1].Page
|
||||
}
|
||||
return wp[x-1].Page
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wp WeightedPages) Next(cur *Page) *Page {
|
||||
for x, c := range wp {
|
||||
if c.Page.UniqueId() == cur.UniqueId() {
|
||||
if x < len(wp)-1 {
|
||||
return wp[x+1].Page
|
||||
}
|
||||
return wp[0].Page
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p WeightedPages) Len() int { return len(p) }
|
||||
func (p WeightedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
||||
func (p WeightedPages) Sort() { sort.Stable(p) }
|
||||
|
Reference in New Issue
Block a user