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

Builtin pagination template doesn´t work with sub root in BaseURL and CanonifyUrls = "false" #1252

Closed
donlzx opened this issue Jul 7, 2015 · 12 comments
Assignees
Milestone

Comments

@donlzx
Copy link

donlzx commented Jul 7, 2015

If .Site.BaseURL contain paths (e.g., example.com/en/), pagination doesn't work correctly. The variables URL, Next.URL, Prev.URL, etc. return incorrect values in the pagination templates, resulting in the following behavior:

http://example.com/en/products/page/2/ (correct link) => http://example.com/products/page/2/ (links in generated pages)

I make it working by hacking the source code (hugolib/pagination.go) around line 276:

urlFactory := newPaginationURLFactory(section)

modified as:

urlFactory := newPaginationURLFactory(helpers.RelURL(section))

Since I am new to Hugo and haven't looked at the source codes before, can someone check this issue and fix it in a correct way?

@bep
Copy link
Member

bep commented Jul 7, 2015

I'm pretty sure the Next.URL etc. are relative to context root, so the examples you give cannot be the string value returned. Can you check?

@donlzx
Copy link
Author

donlzx commented Jul 7, 2015

@bep Actually, I mean the final URL in the generated pages. Fixed my description.

@bep
Copy link
Member

bep commented Jul 7, 2015

And how do you construct the "full URL"?

@donlzx
Copy link
Author

donlzx commented Jul 7, 2015

For testing, I'm just using the default internal template and nothing special:

  {{ range (.Paginator 20).Pages }}
       ....
  {{ end }}
  {{ template "_internal/pagination.html" . }}

The full URLs are constructed by the browser. To be exact, the links to the pages in generated HTML looks like:

 <a href="/products/page/2/">2</a>

It should be:

<a href="/en/products/page/2/">2</a>

@bep
Copy link
Member

bep commented Jul 7, 2015

OK, now I understand it.

The current workaround is to either set CanonifyUrls = "true" or use a custom paginator template.

helpers.RelURL would be the right medicine, but I would do it with the rel variable here:

https://github.com/spf13/hugo/blob/master/hugolib/pagination.go#L367

@bep bep added the Bug label Jul 7, 2015
@bep bep changed the title Pagination ignore baseURL setting Builtin pagination template doesn´t work with sub root in BaseURL and CanonifyUrls = "false" Jul 7, 2015
@donlzx
Copy link
Author

donlzx commented Jul 7, 2015

@bep Using helpers.RelURL() with rel variable doesn't work for me, because rel variable is already of the form /section/page/... and helper.RelURL() doesn't change it.

@bep
Copy link
Member

bep commented Jul 7, 2015

Hmm, that sound a little bit strange. I guess this should be a safe bet, too:

https://github.com/spf13/hugo/blob/master/hugolib/pagination.go#L273

@bep
Copy link
Member

bep commented Mar 1, 2017

Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.

If this is a bug and you can still reproduce this error on the latest release or the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.

@bep bep mentioned this issue Mar 13, 2017
26 tasks
@bep bep self-assigned this Mar 14, 2017
@bep bep added this to the v0.20 milestone Mar 14, 2017
@bep bep removed the Stale label Mar 14, 2017
bep added a commit to bep/hugo that referenced this issue Mar 27, 2017
This is a pretty fundamental change in Hugo, but absolutely needed if we should have any hope of getting "multiple outputs" done.

This commit's goal is to say:

* Every file target path is created by `createTargetPath`, i.e. one function for all.
* That function takes every page and site parameter into account, to avoid fragile string parsing to uglify etc. later on.
* The path creation logic has full test coverage.
* All permalinks, paginator URLs etc. are then built on top of that same logic.

Fixes gohugoio#1252
Fixes gohugoio#2110
Closes gohugoio#2374
Fixes gohugoio#1885
Fixes gohugoio#3102
Fixes gohugoio#3179
Fixes gohugoio#1641
Fixes gohugoio#1989
@bep bep closed this as completed in 6bf010f Mar 27, 2017
@make-github-pseudonymous-again

I still have the same issue in 0.20-DEV with the default paginator. baseurl is https://example.com/bla/ but the paginator generate /page/x urls. Is it supposed to have been fixed?

@moorereason
Copy link
Contributor

Yes, it's fixed been since the 0.20 release. Update your Hugo version. The latest is 0.25.1.

@make-github-pseudonymous-again

Sorry! I thought I had the latest version...

@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 Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants