Group posts by year

This commit is contained in:
Oliver Davies 2021-06-30 08:00:00 +01:00
parent 74422140aa
commit 4a2afa384e

View file

@ -4,7 +4,25 @@ use:
- posts
---
{% set activeYear = false %}
{% for post in data.posts %}
<a href="{{ post.url }}">{{ post.title }}</a>
<br>
{% set postYear = post.date|date('Y') %}
{% if postYear != activeYear %}
{% if activeYear != false %}
</ul>
{% endif %}
{% set activeYear = postYear %}
<h2>{{ postYear }}</h2>
<ul>
{% endif %}
<li>
<a href="{{ post.url }}">{{ post.title }}</a>
- {{ post.date|date('jS F Y') }}
</li>
{% endfor %}