Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.55.0 breaks “prev/next in section” for nested sections #5883

Closed
inwardmovement opened this issue Apr 21, 2019 · 13 comments

Comments

Projects
None yet
4 participants
@inwardmovement
Copy link

commented Apr 21, 2019

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?

@bep

This comment has been minimized.

Copy link
Member

commented Apr 22, 2019

Have you tested your site with 0.55.2?

@inwardmovement

This comment has been minimized.

Copy link
Author

commented Apr 22, 2019

Yes, still broken with 0.55.2 or 0.55.3.

@bep

This comment has been minimized.

Copy link
Member

commented Apr 22, 2019

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

@inwardmovement

This comment has been minimized.

Copy link
Author

commented Apr 22, 2019

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 }}
@larzza

This comment has been minimized.

Copy link

commented Apr 24, 2019

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

@larzza

This comment has been minimized.

Copy link

commented Apr 26, 2019

The last commit that doesn't have this bug:
44f5c1c

The next commit in which it is possible to run hugo without error:
91ef965

Now the bug is present.

@larzza

This comment has been minimized.

Copy link

commented Apr 27, 2019

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

if p1.IsSection() && len(p1.SectionsEntries()) <= 1 {

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 bep added this to the v0.55.5 milestone Apr 29, 2019

@bep

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

@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.

@bep bep modified the milestones: v0.55.5, v0.56 Apr 29, 2019

@bep

This comment has been minimized.

Copy link
Member

commented Apr 29, 2019

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

@bep bep modified the milestones: v0.56, v0.55.5 Apr 29, 2019

@larzza

This comment has been minimized.

Copy link

commented Apr 29, 2019

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 91ef965 "resources/page: Re-introduce .Page.Page" which is before the commit of the date fixes referenced above (1d9dde8).

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! :-)

@larzza

This comment has been minimized.

Copy link

commented Apr 29, 2019

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.

if p1.IsSection() && len(p1.SectionsEntries()) <= 1 {

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.

hugo/hugolib/page.go

Lines 844 to 860 in 4f93f8c

func (s *Site) sectionsFromFile(fi source.File) []string {
dirname := fi.Dir()
dirname = strings.Trim(dirname, helpers.FilePathSeparator)
if dirname == "" {
return nil
}
parts := strings.Split(dirname, helpers.FilePathSeparator)
if fii, ok := fi.(*fileInfo); ok {
if fii.bundleTp == bundleLeaf && len(parts) > 0 {
// my-section/mybundle/index.md => my-section
return parts[:len(parts)-1]
}
}
return parts
}

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

@larzza

This comment has been minimized.

Copy link

commented Apr 29, 2019

@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.

for _, sect := range sectionPages {
if sect.parent != nil {
sect.parent.subSections.sort()
}
for i, p := range sect.Pages {
if i > 0 {
p.NextInSection = sect.Pages[i-1]
}
if i < len(sect.Pages)-1 {
p.PrevInSection = sect.Pages[i+1]
}
}

@bep bep added Bug and removed NeedsInvestigation labels May 1, 2019

@bep bep changed the title 0.55.0 breaks “prev/next in section” navigation 0.55.0 breaks “prev/next in section” for nested sections May 1, 2019

bep added a commit to bep/hugo that referenced this issue May 1, 2019

@bep bep closed this in #5917 May 1, 2019

bep added a commit that referenced this issue May 1, 2019

hugolib: Fix PrevInSection/NextInSection for nested sections
This was broken in Hugo 0.55.0.

Fixes #5883
@Twissi

This comment has been minimized.

Copy link

commented May 7, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.