Skip to content

Instantly share code, notes, and snippets.

@devraj
Created August 21, 2018 04:06
Show Gist options
  • Save devraj/f72afd183f9e31f5929ab4f9b0f3fafa to your computer and use it in GitHub Desktop.
Save devraj/f72afd183f9e31f5929ab4f9b0f3fafa to your computer and use it in GitHub Desktop.
Jekyll Liquid template snippet to list blog items grouped by year and month
<section class="blog-summary">
{% assign postsByYear = site.posts | group_by_exp:"post", "post.date | date: '%Y'" %}
{% for year in postsByYear %}
<h3>{{ year.name }}</h3>
{% assign postsByMonth = year.items | group_by_exp:"post", "post.date | date: '%B'" %}
{% for month in postsByMonth %}
<div class="blog-summary-month">
<h4>{{ month.name }}</h4>
<ol class="blog-post-list">
{% for post in month.items %}
<li>
<p class="blog-title"><a href="{{ post.url }}">{{ post.title }}</a></p>
{% assign author = post.author %}
{% assign author_info = site.data.authors[author] %}
<time datetime="{{ post.date | date: "%Y-%m-%d" }}">{{ post.date | date: "%-d %b %Y" | trim }}</time>, by {{ author_info['name'] }}
</li>
{% endfor %}
</ol>
</div>
{% endfor %}
{% endfor %}
</section>
@devraj
Copy link
Author

devraj commented Aug 21, 2018

Note: the author information in my example is loaded from site.data.authors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment