Jekyll Post Archive Grouped by Year

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{% raw %}
<!-- Check if the date has been output -->
{% assign datePrinted = false %}
<!-- Assign year to something we're not using -->
{% assign currentYear = 1000 %}
<!-- Get number of posts -->
{% assign postCount = archivePosts | size %}
<!-- If no posts, say that -->
{% if postCount == 0 %}
<p>No posts yet</p>
{% endif %}
<!-- Loop thrugh posts -->
{% for post in archivePosts %}
{% assign postYear = post.date | date: "%Y" %}
<!-- Output posts if this is a new year -->
{% unless postYear == currentYear %}
<h2>{{ postYear }}</h2>
{% endunless %}
{% assign currentYear = postYear %}
<!-- Output post -->
<p>
{{ post.date | date: "%d/%m" }} -
<a href="{{ post.url }}">
{{ post.title }}
</a>
</p>
{% endfor %}
{% endraw %}