Jekyll/Liquid Templating: How to group blog posts by year?

前端 未结 8 1296
無奈伤痛
無奈伤痛 2020-11-28 04:45

I\'m rewriting my blog to use Jekyll. Jekyll uses the Liquid templating language so it makes it a little more difficult to learn how to customize.

I\'d like to group

8条回答
  •  天涯浪人
    2020-11-28 04:57

    Variation of Ankit R Gadiya's answer. The inner for loop was displaying the html code. I needed to de-indent it to get it to properly render the markup. I also added the post's excerpt:

    {% assign postsByYear = site.posts | group_by_exp:"post", "post.date | date: '%Y'" %}
    {% for year in postsByYear %}
      

    {{ year.name }}

    {% assign postsByMonth = year.items | group_by_exp:"post", "post.date | date: '%B'" %} {% for month in postsByMonth %}

    {{ month.name }}

      {% for post in month.items %}
    • {{ post.title }}
      {{ post.excerpt }}
    • {% endfor %}
    {% endfor %} {% endfor %}

    Example:

    example

提交回复
热议问题