Michael Profile Picture
Michael Malura
Entwickler - Fotograf - Technologie-Enthusiast

Group jekyll posts by date

29.10.2018 [ code , ramda , javascript ]

I wanted to remove the plain list of blog posts and create a list that is grouped by years and months.

Code

{% raw %}

{% assign years = site.posts | group_by_exp:"post", "post.date | date: '%Y'" %}
{% for year in years %}
  <ul>
  <li>{{year.name}}</li>
  {% assign months = year.items | group_by_exp:"post", "post.date | date: '%B'" %}
  {% for month in months %}
  <ul>
    <li>{{month.name}}</li>
    <ul>
    {% for post in month.items %}
      <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
      </li>
    {% endfor %}
    </ul>
  </ul>
  {% endfor %}
  </ul>
{% endfor %}

{% endraw %}