diff options
author | Ricardo N Feliciano <FelicianoTech@gmail.com> | 2018-09-24 18:06:29 -0400 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-09-26 09:22:43 +0200 |
commit | ad705aac0649fa3102f7639bc4db65d45e108ee2 (patch) | |
tree | ca4a1b132e422d529ed56bb4b9705a23e4f7ff86 /hugolib | |
parent | 52ac85fbc4d4066b5e13df454593597df0166262 (diff) |
hugolib: Introduce Page.NextPage and Page.PrevPage
Introduce new page position variables in order to fix the ordering issue
of `.Next` and `.Prev` while also allowing an upgrade path via
deprecation.
`.NextInSection` becomes `.NextPageInSection`.
`.PrevInSection` becomes `.PrevPageInSection`.
`.Next` becomes a function returning `.PrevPage`.
`.Prev` becomes a function returning `.NextPage`.
Fixes #1061
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/hugo_sites_build_test.go | 14 | ||||
-rw-r--r-- | hugolib/page.go | 16 | ||||
-rw-r--r-- | hugolib/site.go | 8 |
3 files changed, 25 insertions, 13 deletions
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 4c32fa2f6..63e9e52e6 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -268,7 +268,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Equal(t, "/superbob", doc3.URL(), "invalid url, was specified on doc3") b.AssertFileContent("public/superbob/index.html", "doc3|Hello|en") - require.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next") + require.Equal(t, doc2.PrevPage, doc3, "doc3 should follow doc2, in .PrevPage") doc1fr := doc1en.Translations()[0] permalink = doc1fr.Permalink() @@ -398,16 +398,16 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { require.Equal(t, template.URL(""), enSite.RegularPages[0].RSSLink()) // Issue #3108 - next := enSite.RegularPages[0].Next - require.NotNil(t, next) - require.Equal(t, KindPage, next.Kind) + prevPage := enSite.RegularPages[0].PrevPage + require.NotNil(t, prevPage) + require.Equal(t, KindPage, prevPage.Kind) for { - if next == nil { + if prevPage == nil { break } - require.Equal(t, KindPage, next.Kind) - next = next.Next + require.Equal(t, KindPage, prevPage.Kind) + prevPage = prevPage.PrevPage } // Check bundles diff --git a/hugolib/page.go b/hugolib/page.go index bb6dab8e0..8e9e0a7ce 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -505,8 +505,8 @@ type PageMeta struct { } type Position struct { - Prev *Page - Next *Page + PrevPage *Page + NextPage *Page PrevInSection *Page NextInSection *Page } @@ -2308,3 +2308,15 @@ func (p *Page) pathOrTitle() string { } return p.title } + +func (p *Page) Next() *Page { + // TODO Remove in Hugo 0.52 + helpers.Deprecated("Page", ".Next", "Use .PrevPage (yes, not .NextPage).", false) + return p.PrevPage +} + +func (p *Page) Prev() *Page { + // TODO Remove in Hugo 0.52 + helpers.Deprecated("Page", ".Prev", "Use .NextPage (yes, not .PrevPage).", false) + return p.NextPage +} diff --git a/hugolib/site.go b/hugolib/site.go index 0eb4d7dfe..054656f7a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -990,12 +990,12 @@ func (s *Site) setupSitePages() { var siteLastChange time.Time for i, page := range s.RegularPages { - if i < len(s.RegularPages)-1 { - page.Next = s.RegularPages[i+1] + if i > 0 { + page.NextPage = s.RegularPages[i-1] } - if i > 0 { - page.Prev = s.RegularPages[i-1] + if i < len(s.RegularPages)-1 { + page.PrevPage = s.RegularPages[i+1] } // Determine Site.Info.LastChange |