加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – Jekyll数组包含检查

发布时间:2020-12-17 04:02:02 所属栏目:百科 来源:网络整理
导读:我的_config.yaml中有一个数组.让我们说吧 exclude_pages: [ "/404.html","/search.html","/atom.xml","/rss.xml","/index.html","/sitemap.txt" ] 我想要做的是在site.pages的页面循环中排除这些页面.以下是我正在尝试的代码. {% for entry in site.pages %
我的_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 %}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读