Created
August 21, 2018 04:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: the author information in my example is loaded from
site.data.authors