Zola 没有内置的方式来显示存档页面(显示按年份排序的所有帖子标题的页面)。但是,这可以直接在模板中完成:
{% for year, posts in section.pages | group_by(attribute="year") %}
<h2>{{ year }}</h2>
<ul>
{% for post in posts %}
<li><a href="{{ post.permalink }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}
此代码片段假定帖子按日期排序,并且您希望按降序显示存档。如果要按升序显示文章,则需要进一步处理页面列表:
{% 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 %}