Zola: Reverse pagination

Created on 13 Aug 2019  路  17Comments  路  Source: getzola/zola

_I'm not sure if this is a bug report, documentation request, or feature request._

Is it possible to do pagination with a reversed sort_by?

If I do this:

{% for page in section.pages | reverse % }
...
{% endfor %}

I get the pages in the reverse order of whatever the sort_by field is set to in this section's _index.md.

However, if I add paginate_by = 3 to that _index.md, the pages are first sorted (according to sort_by) and then paginated. So, if I do this:

{% for page in paginator.pages | reverse % }
...
{% endfor %}

I get the pages _within_ a chunk (as grouped by pagination) sorted in reverse. That is, I seem to only get pages:

  1. sorted,
  2. grouped by pagination, and
  3. reversed within a group.

But I would like pages:

  1. sorted,
  2. reversed, and then
  3. grouped by pagination.

My particular use case is:

  • I'm using weights to sort pages.
  • I want newer pages to come before older pages.
  • Since weights are non-negative integers, it makes sense to start the oldest page with a weight of 0 and increment by 1 for each newer page.
  • But weights are sorted from least to greatest.

I can work around this by starting with an arbitrarily large weight and decrementing by 1 for each page. However, in the long run, I think it would be better to improve Zola's pagination to support the above (if it doesn't already).

done

Most helpful comment

Maybe date-reverse and weight-reverse to have a consistent language?

All 17 comments

Is it possible to do pagination with a reversed sort_by?

No, pagination is done in Zola itself. Templates cannot generate new files.

A while ago, there was a 3rd pagination method order which was the opposite of weight but it was making the whole pagination super confusing.
A possible way to fix your issue would be to add a reverse_pagination = true config option in a section front-matter but I'm going to wait to have more feedback on that, as 99% of the pagination usecase is with newer-to-older dates.

A possible way to fix your issue would be to add a reverse_pagination = true config option in a section front-matter

That would solve my particular use case, but I'm not sure it's the best general solution.

What about supporting compositionality in sorted_by? I'm not sure if this is the best/right syntax, but I could imagine the following:

sort_by = "weight | reverse"
sort_by = "date | reverse"

At the moment, I can't think of other things you'd use instead of reverse here, but I haven't given it much thought.

I tend to think it would be better to use a modified sort_by option or to define a config option related to sorting instead of to pagination.

It is also common to have asc and -desc using the - and implicit + signs example:

sort_by = "date"  # asc
sort_by "-date"  # desc

This would be a really useful feature. Is it going to be implemented?

looks like this works,

{% for page in paginator.pages | reverse % }

{% endfor %}

That's only reversing the current pager, not the whole pagination.

@jbcurtin that's what I'm currently doing. I'm building a timeline of historical events and it makes much more sense for people to start with the oldest event and move to the most recent.

I kind of like the -date, -weight approach. Is it going to be confusing for people though?

I like -date and -weight ideas too, but more explicit symbols such as reverse-date or weight-descending could be better.

Maybe date-reverse and weight-reverse to have a consistent language?

I agree while "-date" and "-weight" seem to be more parsimonious, date-reverse and weight-reverse make it more obvious as to what's happening.

I'm also most in favour on date-reverse and weight-reverse, that's much clearer imo. Is anyone working on this atm?

Has a consensus been reached on how this should work for the user? I have a tested implementation for reverse pagination that is handled by the paginator itself. All that needs to be done is to couple that new functionality to the front matter. Personally I'm still in favour of "date-reversed" and the like

Not right now. I think in the end I might prefer {date,weight}-reverse but I don't know if people would prefer to see {ascending,descending} rather than reverse to be more explicit.

oh yeah, I actually really like the asc and desc option, that's very clear to me. Would you accept a PR for this? you could leave it open until the specific phrasing is agreed upon since that's a very small change that can get requested down the line. Then at least it's in the system

Should the issue be closed now the PR was merged?

I'll close it once I release 0.12

Was this page helpful?
0 / 5 - 0 ratings