我的 _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 %}
关于ruby - Jekyll 数组包含检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065252/