getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.44k stars 941 forks source link

No `paginator` in `get_section()` #2473

Open charlesrocket opened 5 months ago

charlesrocket commented 5 months ago

There is no way to get paginator's page (page/13, etc) permalink due to standalone variable (#691).

Trying to work around this but get_url() refuses to error:

{% set foo = get_url(path="/posts/page/10142342340101263162411010112") %}

foo should fail in this case since the test site has only 10 posts with the section's pagination set to 2.

Keats commented 5 months ago

get_url doesn't check whether the path exists as some stuff gets added during the build process.

charlesrocket commented 5 months ago

@Keats oh snap, that was my last idea. There are still sitemaps, but I have a grim feeling. All the work on the dynamic PWA cache just got cancelled because there's nowhere to pull pager permalinks from.

Keats commented 5 months ago

Once we have tera2 it should be possible to revamp all the functions to get the paginator but it's far away

charlesrocket commented 5 months ago

@Keats what about something like validate_permalink() since Tera 2 is not happening any time soon?

charlesrocket commented 4 months ago

While there is no built-in solution, one could manually extract pagination settings and calculate required page numbers: charlesrocket/halve-z/pull/27

ZzMzaw commented 1 month ago

Hello,

In order to set up a 'series' feature in a theme, I would need to know if pagination is reversed or not so that I can align series' pages indexes accordingly. Everything works well in the series itself (which is a section) has I have both section and paginator variables. Nevertheless, in the series' pages, I can just do a get_section to retrieve the series' section information and I don't have any way to retrieve pagination information. Unfortunately, applying the workaround just above would not work in my case because my series' section has some content (and not only frontmatter).

Reversing the order of the pages listed in the section when paginate_reversed (or maybe something more meaningful such as sort_reversed) is set to true would work as well for me but I would expect it to have such a huge impact that it doesn't worth it in my opinion.

Even if adding the entire paginator seems not possible, do you think it would be possible to just add paginate_by and paginate_reversed in the serialized section returned by get_section? https://github.com/getzola/zola/blob/051becaa1c681165c9f32d30e4e4bde3952765bc/components/content/src/ser.rs#L206-L229

If yes, I can try to tackle it and propose a PR in the weeks to come. If you would prefer me to open a new issue instead of reusing this one, please tell me.

Thanks for your help and support.

Keats commented 1 month ago

Even if adding the entire paginator seems not possible, do you think it would be possible to just add paginate_by and paginate_reversed in the serialized section returned by get_section

That would be fine yes

ZzMzaw commented 1 month ago

That would be fine yes

Thanks for your feedback.

This is my first contribution and I was not able to figure out which branch I should push this modification to (master or next). Is master dedicated to bug fixing the current version only or should we consider this small evolution to be part of it as well?

Thanks in advance for your help and support.

Keats commented 1 month ago

master is only for docs update, all new features/bug fixes go on the next branch