diff options
author | spf13 <steve.francia@gmail.com> | 2014-11-27 23:08:06 -0500 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-11-27 23:15:25 -0500 |
commit | b719ba7e2bd612e85e539b17569ed15066ebcc07 (patch) | |
tree | 0bdb8a514c7afb3dff2895a11a02daa6f96148e1 /hugolib/taxonomy.go | |
parent | 78316903a24af73b476032295caba56588558924 (diff) |
Adding Prev/Next functionality to all lists of pages (sections, taxonomies, etc)
Diffstat (limited to 'hugolib/taxonomy.go')
-rw-r--r-- | hugolib/taxonomy.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/hugolib/taxonomy.go b/hugolib/taxonomy.go index 93bd78f68..fdba1e56e 100644 --- a/hugolib/taxonomy.go +++ b/hugolib/taxonomy.go @@ -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) } |