如何在摘录中删除一些Liquid标签?

拉斐尔

我在Jekyll网站上有几个元素,它们不能很好地摘录,特别是在RSS feed中使用时。由于它们是由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)

不过,我没有看到如何检查标记是否呈现摘录。倾销contentx context.environmentscontext.scopescontext.registers没有透露任何有用的东西。

我怎样才能做到这一点?

拉斐尔

对于Jekyll或Liquid,我没有解决方案。但是,有一个相当简单的解决方法:使用CSS隐藏有问题的元素。

假设您有这样的事情:

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

然后使用CSS隐藏元素:

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章