1

我的 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.environments转储的contentxcontext.scopescontext.registers没有透露任何有用的信息。

我怎样才能做到这一点?

4

1 回答 1

1

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

假设你有这样的事情:

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

然后使用 CSS 隐藏元素:

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

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

于 2016-02-26T12:10:33.700 回答