簡體   English   中英

Jekyll數組包含檢查

[英]Jekyll array contains check

我的_config.yaml中有一個數組。 讓我們說吧

exclude_pages: [ "/404.html", "/search.html", "/atom.xml", "/rss.xml", "/index.html", "/sitemap.txt" ]

我想要做的是在site.pages的頁面循環中排除這些頁面。 以下是我正在嘗試的代碼。

{% for entry in site.pages %}
    {% if site.exclude_pages contains entry.url %}
        <!-- Do Nothing -->
    {% else %}
        <!-- Show Page -->
    {% endif %}
{% endfor %}

但不知怎的,它沒有發生。 此代碼中的所有頁面都被忽略。

知道我在這里缺少什么嗎?

試試:

exclude_pages: [ "index.html", "anyfolder/index.html" ]

然后使用entry.path循環而不是entry.url

{% for entry in site.pages %}
    {% if site.exclude_pages contains entry.path %}
        <!-- Do Nothing -->
    {% else %}
        <!-- Show Page -->
    {% endif %}
{% endfor %}

根據模板文檔 ,我嘗試使用Where Expression with containsunless

{{ assign entries = site.pages | where_exp:"item", "unless item.url contains site.exclude_pages" }}
{% for entry in entries %}
   <!-- Show Page -->
{% endfor %}

請參閱示例實時代碼如何在我的github站點中生成feed.json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM