【问题标题】:Archive Jekyll Posts by Year [duplicate]按年份存档 Jekyll 帖子 [重复]
【发布时间】:2014-08-03 05:02:14
【问题描述】:

如果您愿意,我正在制作我网站上所有帖子的“存档”。我想收集一年的所有帖子。但是,此代码可以正常工作;我希望它在需要时生成<h2>2014</h2>。

基本上,如果年份是 2014 年,则渲染 <h2>2014</h2> 并制作一个 <ul> 来自给定的所有帖子(带有期刊类别)年。

如果有人知道任何按年存档的 .rb 插件,请告诉我!

<h2>2014</h2>
{% for post in site.categories.journal %}
    {% capture year %}{{post.date | date: "%Y"}}{% endcapture %}
        {% if year == "2014" %}
                <ul class="posts-in-year">
                    <li><p><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a> &mdash; {{ post.date | date: "%B %d" }}</p></li>
                </ul>
        {% endif %}
{% endfor %}

我希望它看起来像这样:

【问题讨论】:

标签: html ruby jekyll


【解决方案1】:
{% for post in site.categories.journal %}
  {% capture currentyear %}{{post.date | date: "%Y"}}{% endcapture %}
  {% if currentyear != year %}
     <h2>{{ currentyear }}</h2>
    {% capture year %}{{currentyear}}{% endcapture %} 
  {% endif %}
  <ul class="posts-in-year">
    <li><p><a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}    </a> &mdash; {{ post.date | date: "%B %d" }}</p></li>
  </ul>
{% endfor %}

【讨论】:

    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 2017-01-28
    • 2016-05-18
    • 1970-01-01
    • 2023-03-11
    相关资源
    最近更新 更多