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

前端 未结 8 1291
無奈伤痛
無奈伤痛 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 05:16

    Try:

    {% for post in site.posts  %}
      {% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
    
      {% if forloop.first %}
      

    {{this_year}}

      {% else %} {% if this_year != last_year %}

    {{this_year}}

      {% endif %} {% endif %}
    • {{ post.title }}
    • {% if forloop.last %}
    {% endif %} {% capture last_year %}{{ this_year }}{% endcapture %} {% endfor %}

提交回复
热议问题