Hugo: 0.55.0 breaks “prev/next in section” for nested sections

Created on 21 Apr 2019  Â·  13Comments  Â·  Source: gohugoio/hugo

The 0.55.0 update breaks the "prev/next in section" navigation that was working on 0.54: .PrevInSection and .NextInSection are empty. See my code here.

nil pointer evaluating page.Page.URL

Seems not related to page's .URL deprecation: same error with .Permalink. Apparently the only thing modifying sections in 0.55.0 is the following:

Fix default date assignment for sections 1d9dde82 @bep #5784

Could it be related to it?

Bug

Most helpful comment

My experience is:

  • previous/next works as expected for pages in a top level section
  • for pages located in a nested section .PrevInSection and .NextInSection returns <nil>

The behavior was introduced between 0.54.0 and 0.55.0

All 13 comments

Have you tested your site with 0.55.2?

Yes, still broken with 0.55.2 or 0.55.3.

I tested your site, and it does not "break" for me.

Did you test the navigation here? It works in 54 but not in 55.

I updated the repo and wrote a little test here that returns full with v54 and always empty with v55, you can test it locally:

{{if .PrevInSection}}full in v54{{ end }}
{{if not .PrevInSection}}empty in v55{{ end }}

My experience is:

  • previous/next works as expected for pages in a top level section
  • for pages located in a nested section .PrevInSection and .NextInSection returns <nil>

The behavior was introduced between 0.54.0 and 0.55.0

The last commit that doesn't have this bug:
https://github.com/gohugoio/hugo/commit/44f5c1c14cb1f42cc5f01739c289e9cfc83602af

The next commit in which it is possible to run hugo without error:
https://github.com/gohugoio/hugo/commit/91ef9655aaf2adea3a044bf9a464908084917a98

Now the bug is present.

By removing && len(p1.SectionsEntries()) <= 1 from prepareInits in site.go prev/next again appears in a nested subsection like it should.

https://github.com/gohugoio/hugo/blob/ea529c847ebc0267c6d0426cc8f77d5c76c73fe4/hugolib/site.go#L223

For now I haven't explored if this is all that has to be done (it's my first dive into the hugo source) but if my findings is correct it should be a place to start.

@bep Do you agree on that this is a bug?

@bep Do you agree on that this is a bug?

Note that next/prev in section has always been a "top section only", so the differences you see here is probably due to fixes in Hugo's date handling. But that is hard to see with such a complex example. If you still think there is an issue here, but it would be good if you could narrow it down to a simpler demo site that I can wrap my small head around.

Ignore my last comment, I think I understand what's going on. I will have a look at it.

Maybe the issue I and @inwardmovement have isn't exactly the same?

  • I have used previous/next on subsections without a problem before 0.55.0.
  • For me , it still works as expected for top sections >0.55.0.
  • First time Next/prev doesn't appear on nested subsections is in the commit https://github.com/gohugoio/hugo/commit/91ef9655aaf2adea3a044bf9a464908084917a98 "resources/page: Re-introduce .Page.Page" which is before the commit of the date fixes referenced above (https://github.com/gohugoio/hugo/commit/1d9dde82a0577d93eea8ed0a7ec0b4ae3068eb19).

I still think this is an issue. If it was an unintended side effect that prev/next worked on nested subsections before, it was a really good one! :-)

Taking a new glance at the source it seems to me that doing what I suggested above should solve my part of the problem, i.e. introduce next/prev on nested subsections.

That is:

By removing && len(p1.SectionsEntries()) <= 1 from prepareInits in site.go prev/next again appears in a nested subsection like it should.

https://github.com/gohugoio/hugo/blob/ea529c847ebc0267c6d0426cc8f77d5c76c73fe4/hugolib/site.go#L223

What p1.SectionsEntries() comes down to is the length of the splitted parent path, and by removing the check and thus allowing a path >1, next/prev is allowed on nested subsections.

https://github.com/gohugoio/hugo/blob/4f93f8c670b26258dc7e3a613c38dbc86d8eda76/hugolib/page.go#L844-L860

@bep Do you think there are any unfortunate side effects of this approach?

@bep If I'm not mistaken this code snippet in 0.54.0 (which was deleted in 0.55.0 and replaced by the snippet in site.go referenced above) is the reason to why nested subsections had prev/next functionality. Here a range over all section pages (i.e. top and nested sections) are performed and next/previous in section is set.

https://github.com/gohugoio/hugo/blob/5383fe458c0ce24e1623dd91e795d4fb5772ae9d/hugolib/site_sections.go#L336-L348

@bep Thanks for the fix! Just verified and works for nested subsections. (v0.55.5)
Just wondering if this is still just a side effect or if I can keep using PrevInSection/NextInSection for my nested subsection nav.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carandraug picture carandraug  Â·  3Comments

antifuchs picture antifuchs  Â·  3Comments

crash-dive picture crash-dive  Â·  3Comments

vielmetti picture vielmetti  Â·  3Comments

sigma picture sigma  Â·  3Comments