Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Liquid Template language to group jekyll blog posts by year.
{% for post in site.posts %}
{% capture current_year %}
{{post.date | date: "%Y"}}
{% endcapture %}
{% if current_year != previous_year %}
{% assign previous_year = current_year %}
<h4 class="post-header">
<span role="img" aria-label="icon-book" aria-hidden="true">🎉</span>
{{ current_year }}
</h4>
{% endif %}
<article class="posts">
<span class="posts-date">{{ post.date | date: "%b %d" }}</span>
<header class="posts-header">
<h4 class="posts-title">
<a href="{{ post.url }}">{{ post.title | escape }}</a>
</h4>
</header>
</article>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment