【问题标题】:Wildcard match in Liquid tag?Liquid标签中的通配符匹配?
【发布时间】:2015-06-26 10:43:41
【问题描述】:

我正在尝试从我网站的 RSS 提要中过滤掉部分帖子。我想要帖子的其余部分,但只想删除某些部分。

有没有办法以某种方式过滤掉它?我查看了这些 Liquid 标签/过滤器,发现最接近的是 removereplace,但它们似乎在字面上匹配。

我基本上在我的feed.xml 中尝试这样做:

{{ post.content | replace:'<span class="no-rss">*</span>','' | cdata_escape }}

有没有办法在这些过滤器中使用通配符,或者以其他方式实现我不知道的?我的 Google-fu 在这个上已经干涸了。

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    两种解决方案:

    在帖子中使用摘录

    您要在 Feed 中注入的部分帖子位于帖子的开头。

    使用excerpt

    用液体过滤器隔离部分内容

    如果您在page(他们没有摘录)中,或者在帖子中并且想要选择内容的特定部分,您可以使用液体过滤器。 string.splitarray filters

    在任何帖子或页面中

    ---
    your front matter variables here
    ---
    Head of my document
    <!-- start -->
    Text to extract
    <!-- end -->
    Bottom of my document
    

    在你的 RSS 中

    {% for p in site.posts %}
        {% if p.content contains "<!--start-->" %}
            {% assign extract = p.content | split: "<!--start-->" | last | split: "<!--end-->" | first %}
            {{ extract }}
        {% else %}
            {{ p.content }}
        {% endif %}
    {% endfor %}
    

    【讨论】:

      【解决方案2】:

      您可以摆脱应用到它的样式类,而不是删除整个跨度:

      {{ post.content | remove: ' class="no-rss"' | cdata_escape }}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-14
        • 2022-06-11
        • 2017-06-17
        • 2014-08-11
        • 2021-07-17
        • 2010-12-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多