-
-
Save tuananh/7432553 to your computer and use it in GitHub Desktop.
--- | |
layout: default | |
title: Archive | |
--- | |
<div class="post"> | |
<h2>Archive</h2> | |
<ul> | |
{% for post in site.posts %} | |
{% unless post.next %} | |
<h3>{{ post.date | date: '%Y %b' }}</h3> | |
{% else %} | |
{% capture year %}{{ post.date | date: '%Y %b' }}{% endcapture %} | |
{% capture nyear %}{{ post.next.date | date: '%Y %b' }}{% endcapture %} | |
{% if year != nyear %} | |
<h3>{{ post.date | date: '%Y %b' }}</h3> | |
{% endif %} | |
{% endunless %} | |
<li><a href="{{ post.url }}">{{ post.title }}</a></li> | |
{% endfor %} | |
</ul> | |
</div> |
Thanks @trevorknight. I've adapted your group_by_exp
example into my by-year implementation, and it shaved a good 12% off the overall Jekyll build time. ⚡ 💯
@trevorknight perfect!
Yours is an elegant solution to the shortcomings of previous versions of Jekyll. Luckily in late 2016, Jekyll added a
group_by_exp
filter that can do this much more cleanly.<h2>Archive</h2> {% assign postsByYearMonth = site.posts | group_by_exp:"post", "post.date | date: '%Y %b'" %} {% for yearMonth in postsByYearMonth %} <h3>{{ yearMonth.name }}</h3> <ul> {% for post in yearMonth.items %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} </ul> {% endfor %}
Documentation can be found on the Jekyll Templates page.
Thanks. Gotta update my jekyll template
Yours is an elegant solution to the shortcomings of previous versions of Jekyll. Luckily in late 2016, Jekyll added a
group_by_exp
filter that can do this much more cleanly.<h2>Archive</h2> {% assign postsByYearMonth = site.posts | group_by_exp:"post", "post.date | date: '%Y %b'" %} {% for yearMonth in postsByYearMonth %} <h3>{{ yearMonth.name }}</h3> <ul> {% for post in yearMonth.items %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} </ul> {% endfor %}
Documentation can be found on the Jekyll Templates page.
This code block solved my doubts about this filter, I searched all over Google and couldn't find such a perfect code block, thanks again for your answer!
Yours is an elegant solution to the shortcomings of previous versions of Jekyll. Luckily in late 2016, Jekyll added a
group_by_exp
filter that can do this much more cleanly.Documentation can be found on the Jekyll Templates page.