Skip to content

Instantly share code, notes, and snippets.

@piharpi
Created November 24, 2019 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piharpi/6164a17dc823cd33a4306ea6e6c88bf1 to your computer and use it in GitHub Desktop.
Save piharpi/6164a17dc823cd33a4306ea6e6c88bf1 to your computer and use it in GitHub Desktop.
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