Skip to content

Commit

Permalink
hugolib: Simplify Prev/Next
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Mar 12, 2018
1 parent 0dbf79c commit 79dd7cb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hugolib/pagesPrevNext.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ package hugolib
// Prev returns the previous page reletive to the given page.
func (p Pages) Prev(cur *Page) *Page {
for x, c := range p {
if c.UniqueID() == cur.UniqueID() {
if c.Eq(cur) {
if x == 0 {
// TODO(bep) consider return nil here to get it line with the other Prevs
return p[len(p)-1]
}
return p[x-1]
Expand All @@ -29,10 +30,11 @@ func (p Pages) Prev(cur *Page) *Page {
// Next returns the next page reletive to the given page.
func (p Pages) Next(cur *Page) *Page {
for x, c := range p {
if c.UniqueID() == cur.UniqueID() {
if c.Eq(cur) {
if x < len(p)-1 {
return p[x+1]
}
// TODO(bep) consider return nil here to get it line with the other Nexts
return p[0]
}
}
Expand Down

0 comments on commit 79dd7cb

Please sign in to comment.