如何去掉 post 摘录中的一些 Liquid 标签?
How to get rid of some Liquid tags in post excerpts?
我的 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
、context.scopes
和 context.registers
的 contentx 没有显示任何有用的信息。
我该怎么做?
我没有 Jekyll 或 Liquid 级别的解决方案。不过,有一个相当简单的解决方法:使用 CSS.
隐藏有问题的元素
假设你有这样的东西:
<div class="excerpt">
{{ post.excerpt }}
</div>
然后使用CSS隐藏元素:
div.excerpt {
.footnote,.footnotes,.marginnote {
display: none;
}
}
类 显然取决于您使用的 Markdown 引擎、插件和主题。
我的 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
、context.scopes
和 context.registers
的 contentx 没有显示任何有用的信息。
我该怎么做?
我没有 Jekyll 或 Liquid 级别的解决方案。不过,有一个相当简单的解决方法:使用 CSS.
隐藏有问题的元素假设你有这样的东西:
<div class="excerpt">
{{ post.excerpt }}
</div>
然后使用CSS隐藏元素:
div.excerpt {
.footnote,.footnotes,.marginnote {
display: none;
}
}
类 显然取决于您使用的 Markdown 引擎、插件和主题。