我有一個使用Jekyll Now在 Github Pages 上創建的博客
默認的 Index.html 看起來像這樣
---
layout: default
---
<div >
{% for post in site.posts %}
<article >
<h2><a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></h2>
<div >
{{ post.excerpt }}
</div>
<a href="{{ site.baseurl }}{{ post.url }}" >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 >
...
</article>
{% endif %}
{% endfor %}
還嘗試使用包含而不是 indexOf,這也不起作用。在這兩種情況下,我都沒有在登錄頁面上看到任何鏈接的帖子。
我該怎么做呢?
uj5u.com熱心網友回復:
我通過在我不想包含的頁面的前端添加一個類別來做到這一點。
即類別:noshow
然后將 index.html 更改為
{% for post in site.posts %}
{% unless post.category == "noshow" %}
.....
{%endunless}
{%endfor}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/349147.html
