ruby - Jekyll 数组包含检查

标签 ruby templates jekyll liquid

我的 _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/

相关文章:

ruby - 如何在 Ruby 中实现链表的 #pop

css - 使用 Jekyll 和 Octopress 部署 CSS

ruby-on-rails - 单表继承还是类表继承?

templates - 将列表映射到 HTML 并将结果插入 Play 2.0 模板中

c++ - 基于模板类型的不同类型

c++ - 如何 std::bind 模板函数?

web - Jekyll - Front Matter 默认不工作

Jekyll 帖子摘录 : How to know if there was an auto generated excerpt?

ruby-on-rails - 在 OSX Mavericks 之后无法加载此类文件 -- script/../config/boot (LoadError)

ruby - "Command-Query Separation"规则的异常(exception)情况?