如何在Jekyll中使用if语句修改.md文件?

时间:2019-01-18 23:10:23

标签: jekyll

我目前正在使用Jekyll来运行一个列出事件的小型站点。我只想在我的网站上显示当前和将来的事件。我正在使用Jekyll的博客文章列出事件。帖子代表一个事件。

我想做的是,当发布时间超过当前日期时,在.md文件中添加一行,显示为“ published:false”。这样,活动结束后的第二天,该帖子就会自动取消发布。

我能够以正确的顺序列出事件(按事件日期列出),并获取网站的当前日期。因此,我可以编写IF语句以将每个事件与当前日期进行比较,以查看它是否与我的问题匹配。

{% comment %}
    Displays all of the people from the _date2/ collection in a list. Also includes a link to post pages.
{% endcomment %}

<div class="container py-5">
  <div class="row">
    <div class="col-12">
      <h2>Special Events</h2>
      <hr class="m-0">
    </div>
  </div>

  <div class="row">
  {% assign currentDate = site.time %}
  {% assign sorted = (site.date2 | sort: 'event_date') %}
  {% for item in sorted %}
    {% if item.event_date >= currentDate %}
    <div class="col-12 mt-3">
      <div class="row d-flex align-items-center">
        <div class="pr-0 pt-2 px-sm-3 col-3 col-md-4">
          {% if item.banner_image and item.banner_image != "" %}
              <img alt="{{ item.title }}" src="{{ item.banner_image | absolute_url }}" class="img-fluid">
          {% else %}
              <img alt="{{ item.title }}" src="{{ '/img/placeholder.png' | absolute_url }}" class="img-fluid">
          {% endif %}
        </div>
        <div class="col-9 col-md-8">
          <h3 class="mb-0 mb-md-2">{{ item.event_date | date: "%A - %B %-d, %Y" }}</h3>
          <h4 class="mb-0 mb-md-2"><a href="{{ item.url | absolute_url }}">{{ item.title }}</a></h4>
          <p class="mb-0 mb-md-3">{{ item.sub_heading }}</p>
        </div>
      </div>
    </div>
    {% else %}

    Append "published: false" to file

    {% endif %}

  {% endfor %}
  </div>
</div>

我还没有任何结果,但是我正在尝试阅读文档以弄清这一点。我希望能收到社区的声音,主要是因为我觉得我在Google上提出了错误的问题。任何方向对此将不胜感激。

0 个答案:

没有答案