[英]Github Pages: adding an if condition in index.html
I have a blog created on Github Pages using Jekyll Now我有一个使用Jekyll Now在 Github Pages 上创建的博客
The default Index.html looks like this默认的 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>
This creates a landing page where the titles of all the posts you have made in the _posts directory are displayed with a link.这将创建一个登录页面,其中显示您在 _posts 目录中发布的所有帖子的标题和链接。
Looking at the {% for ... %}
& {% endfor %}
& the final static HTML, it seems as if when building the page, the for tag is actually iterated & the final HTML contains a list of actual titles.查看
{% for ... %}
& {% endfor %}
& 最终的静态 HTML,似乎在构建页面时,实际上迭代了 for 标签 & 最终的 HTML 包含实际标题的列表。
I want to change this so that not all posts are listed.我想更改此设置,以便不列出所有帖子。 I do not want to list any post whose title contains the string "BEINGWRITTEN"
我不想列出任何标题包含字符串“BEINGWRITTEN”的帖子
I tried stuff like我试过类似的东西
{% for post in site.posts %}
{% if (post.title.indexOf('BEINGWRITTEN') == -1) %}
<article class="post">
...
</article>
{% endif %}
{% endfor %}
Also tried with includes instead of indexOf, that also doesn't work.还尝试使用包含而不是 indexOf,这也不起作用。 Both cases, I don't see any posts linked at all on the landing page.
在这两种情况下,我都没有在登录页面上看到任何链接的帖子。
How do I do this?我该怎么做呢?
I did this by adding a category in the front matter of the page I don't want included.我通过在我不想包含的页面的前端添加一个类别来做到这一点。
ie category: noshow即类别:noshow
Then changed the index.html to然后将 index.html 更改为
{% for post in site.posts %}
{% unless post.category == "noshow" %}
.....
{%endunless}
{%endfor}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.