mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-28 14:01:04 +00:00
hugolib: Simplify Prev/Next
This commit is contained in:
parent
0dbf79c2f8
commit
79dd7cb31a
1 changed files with 4 additions and 2 deletions
|
@ -16,8 +16,9 @@ package hugolib
|
||||||
// Prev returns the previous page reletive to the given page.
|
// Prev returns the previous page reletive to the given page.
|
||||||
func (p Pages) Prev(cur *Page) *Page {
|
func (p Pages) Prev(cur *Page) *Page {
|
||||||
for x, c := range p {
|
for x, c := range p {
|
||||||
if c.UniqueID() == cur.UniqueID() {
|
if c.Eq(cur) {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
|
// TODO(bep) consider return nil here to get it line with the other Prevs
|
||||||
return p[len(p)-1]
|
return p[len(p)-1]
|
||||||
}
|
}
|
||||||
return p[x-1]
|
return p[x-1]
|
||||||
|
@ -29,10 +30,11 @@ func (p Pages) Prev(cur *Page) *Page {
|
||||||
// Next returns the next page reletive to the given page.
|
// Next returns the next page reletive to the given page.
|
||||||
func (p Pages) Next(cur *Page) *Page {
|
func (p Pages) Next(cur *Page) *Page {
|
||||||
for x, c := range p {
|
for x, c := range p {
|
||||||
if c.UniqueID() == cur.UniqueID() {
|
if c.Eq(cur) {
|
||||||
if x < len(p)-1 {
|
if x < len(p)-1 {
|
||||||
return p[x+1]
|
return p[x+1]
|
||||||
}
|
}
|
||||||
|
// TODO(bep) consider return nil here to get it line with the other Nexts
|
||||||
return p[0]
|
return p[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue