在 gh-pages Jekyll 中是否可以在不评估 liquid 标签的情况下扩展 {{content}} ?

Is it possible in gh-pages Jekyll to have {{content}} expand without evaluating liquid tags?

我正在尝试为我的项目文档使用 GitHub 页,但它包含生成的 html 文件,结果证明这些文件具有非法液体标签。我不需要任何超出 _layout 本身的扩展,但据我所知,文章内容本身中的任何 {% ... %} 标签也会被评估,似乎没有办法抑制它,除了添加{% raw %}...{% endraw %} 围绕每篇文章的全部内容。

有什么方法可以在调用站点执行此操作吗?类似 {{ content | unrendered }} 的东西会很棒。

注意:这似乎与许多其他人相反的问题,他们在预渲染上下文中使用 page.content 并希望它被渲染;我试过 page.content 但据我所知,我的情况完全一样,所以没有骰子。

page.content 在 jekyll 2.x 时代是原始的。现在是渲染内容。

您可以使用 hook plugin 在任何页面上添加 page.raw 字段。

Jekyll::Hooks.register :pages, :pre_render do |document|
  document.data['raw'] = document.content
end

如果您想对帖子和 collections 项执行相同的操作,请使用文档挂钩:

Jekyll::Hooks.register :documents, :pre_render do |document|

注:

  • :pre_render 钩子中 document.content 包含原始内容
  • :post_render 钩子中 document.content 包含呈现的内容