Fix erroring suggestion in docs (#2087)

The docs suggest `reverse` after `group_by`, but that causes an error.
This commit is contained in:
Koen Bolhuis 2023-02-08 22:31:18 +01:00 committed by GitHub
parent 3af1815ea3
commit 9ea33f0dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,5 +19,16 @@ all post titles ordered by year). However, this can be accomplished directly in
``` ```
This snippet assumes that posts are sorted by date and that you want to display the archive This snippet assumes that posts are sorted by date and that you want to display the archive
in descending order. If you want to show articles in ascending order, add a `reverse` filter in descending order. If you want to show articles in ascending order, you need to further
after `group_by`. process the list of pages:
```jinja2
{% set posts_by_year = section.pages | group_by(attribute="year") %}
{% set_global years = [] %}
{% for year, ignored in posts_by_year %}
{% set_global years = years | concat(with=year) %}
{% endfor %}
{% for year in years | reverse %}
{% set posts = posts_by_year[year] %}
{# (same as the previous snippet) #}
{% endfor %}
```