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

Next/NextInSection and Prev/PrevInSection are flipped? #9158

Closed
Wuzzy2 opened this issue Nov 11, 2021 · 5 comments
Closed

Next/NextInSection and Prev/PrevInSection are flipped? #9158

Wuzzy2 opened this issue Nov 11, 2021 · 5 comments

Comments

@Wuzzy2
Copy link

Wuzzy2 commented Nov 11, 2021

It seems that Next/NextInSection and Prev/PrevInSection (page vars) are flipped. I.e. the "next" actually returns the previous page and vice-versa.

How to reproduce

Create a number of content pages named 1.md, 2.md, ... Give them a weight equal to their pre-suffix file name. According to the docs, lower weight has higher precedence, which means it must come first.

Then for the content page layout, do this:

<p>
Next: {{ .Next }}
Prev: {{ .Prev }}
NextInSection: {{ .NextInSection }}
PrevInSection: {{ .PrevInSection }}
</p>

Start hugo server and point the broser to one of the content page 3.

Expected: Next and NextInSection show 4, and Prev and PrevInSection show 2.
Actual result: Next and NextInSection show 2, and Prev and PrevInSection show 4.

I also tested this with a {{ range .Site.Pages.ByWeight }} but for this, the pages oddly appear in the expected order (1, 2, 3, 4, ...). It seems only those specal page vars are affected.

Compability concerns

If my bug report is correct and not due to my own failure, and you want to fix the bug, I have concerns about compability. If you fix it just by flipping the variables, this might cause breakage of existing sites that depend on this bug. A good solution would be to deprecate those symbols, still support them, but print a warning when they are used. And then introduce symbols that have similar names but use the correct behavior.

What version of Hugo are you using (hugo version)?

hugo v0.89.2+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

Yes.

@bep
Copy link
Member

bep commented Nov 11, 2021

We have had this discussion before, use the search function. Ask further questions at https://discourse.gohugo.io/

@bep bep closed this as completed Nov 11, 2021
@Wuzzy2
Copy link
Author

Wuzzy2 commented Nov 11, 2021

This is neither a question nor a discussion, but a bug report. The search function yielded nothing.

The first issue is not the same as my issue. In the scenario I presented, .Next and .NextInSection return the same value, not the "opposite" one.
The second issue is also not the same as my issue, because that was a feature request.

Also note that in my test, I specifically have set the weight for all pages, something which the other issues did not do. So that means this behavior cannot be explained by default sort order. I'm still believing something weird and unintentional is happening here.

Also, I know how to work around this and I don't need support. This is besides the point. The point is that Next/Prev do the opposite than what the documentation claims they do. Which means either Hugo has incorrect behavior, or the documentation is incorrect or misleading.

@yannh
Copy link

yannh commented Dec 19, 2021

Hi @Wuzzy2 , I am seeing the same issue, sorting by weight with hugo v0.91.0-D1DC0E9A linux/amd64 BuildDate=2021-12-17T09:50:20Z VendorInfo=gohugoio

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants