【问题标题】:Comparing dates in Jekyll在 Jekyll 中比较日期
【发布时间】:2016-11-27 21:55:26
【问题描述】:

我正在尝试将当前日期与 jekyll/liquid 中的帖子日期进行比较。如果当前日期小于帖子的日期,那么我想显示帖子标题。

到目前为止,这是我的代码:

 <header class="announce-ticker">
  <div class="container">
    {% capture currentDate %}
      {{ 'now' | date: '%s'}}
    {% endcapture %}
    {% assign eventCount = 0 %}
    {% assign eventPosts = site.posts %}
    {% for post in eventPosts %}
      {% capture postDate %}
        {{ post.date | date: '%s'}}
      {% endcapture %}
      {% if currentDate < postDate %}
        {% post.title %}
        {% assign eventCount = 1 %}
      {% endif %}
      {{ currentDate}}
      {{ postDate }}
    {% endfor %}

    {% if eventCount == 0 %}
      <p>No events</p>
    {% endif %}

  </div>
</header>

我的问题是当它大于当前日期时它没有显示帖子。

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    默认情况下不发布未来日期的帖子。通过命令行启用它们的基本方法是使用future 选项:

    jekyll serve --future
    

    或者,您可以将future 参数添加到您的_config.yml

    future: true
    

    this article 中有更多选项。

    【讨论】:

    • 我还将日期强制转换为整数,它似乎也能正常工作!
    猜你喜欢
    • 2021-11-05
    • 2016-03-04
    • 2013-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多