【发布时间】:2021-12-16 00:06:15
【问题描述】:
我在 Github 页面上使用 Jekyll Now 创建了一个博客
默认的 Index.html 是这样的
---
layout: default
---
<div class="posts">
{% for post in site.posts %}
<article class="post">
<h2><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h2>
<div class="entry">
{{ post.excerpt }}
</div>
<a href="{{ site.baseurl }}{{ post.url }}" class="read-more">Read More</a>
</article>
{% endfor %}
</div>
这将创建一个登录页面,您在 _posts 目录中创建的所有帖子的标题都将显示并带有链接。
查看{% for ... %} & {% endfor %} & 最终的静态 HTML,似乎在构建页面时,for 标签实际上是迭代的,最终的 HTML 包含一个实际标题列表。
我想更改此设置,以便不会列出所有帖子。我不想列出任何标题包含字符串“BEINGWRITTEN”的帖子
我尝试过类似的东西
{% for post in site.posts %}
{% if (post.title.indexOf('BEINGWRITTEN') == -1) %}
<article class="post">
...
</article>
{% endif %}
{% endfor %}
还尝试使用包含而不是 indexOf,这也不起作用。在这两种情况下,我都没有在着陆页上看到任何链接的帖子。
我该怎么做?
【问题讨论】:
标签: if-statement github conditional-statements github-pages blogs