【问题标题】:How to get rid of some Liquid tags in post excerpts?如何摆脱帖子摘录中的一些液体标签?
【发布时间】:2015-09-24 14:19:41
【问题描述】:

我的 Jekyll 网站中有几个元素不能很好地用于摘录,尤其是在 RSS 提要中使用时。由于它们是由 Liquid 标签创建的(在自定义插件中实现),我认为它应该很容易做到。这样的事情看起来很谨慎:

module Jekyll
  class MyTag < Liquid::Tag
    def initialize(tag_name, text, tokens)
      super
    end

    def render(context)
      if <in excerpt>
        ""
      else
        "this should not be in an excerpt"
      end
    end
  end
end

Liquid::Template.register_tag('mytag', Jekyll::MyTag)

不过,我不知道如何检查标签是否呈现为摘录。转储context.environmentscontext.scopescontext.registers 的内容并没有发现任何有用的信息。

我该怎么做?

【问题讨论】:

    标签: ruby jekyll liquid jekyll-extensions


    【解决方案1】:

    我没有 Jekyll 或 Liquid 级别的解决方案。不过,有一个相当简单的解决方法:使用 CSS 隐藏有问题的元素。

    假设你有这样的事情:

    <div class="excerpt">
      {{ post.excerpt }}
    </div> 
    

    然后使用 CSS 隐藏元素:

    div.excerpt {
      .footnote,.footnotes,.marginnote {
        display: none;
      }
    } 
    

    显然,这些类取决于您使用的 Markdown 引擎、插件和主题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多