在 Jekyll 前言中包含 HTML(post 标题)

Include HTML in Jekyll front matter (post title)

如何将 HTML 标签放在 Jekyll post 的 (YAML-encoded) 前面,并阻止此 HTML 在最终输出中被转义?我的内容,包括 post 的标题,除了主要页面语言外还使用多种语言,这需要使用 span lang="XX" 标签为屏幕阅读器和某些自动提取进行适当的标记。但是,尝试编写以下内容:

---
layout: post
title: A post that says <span lang="fr">Bonjour</span> and <span lang="es">Hola</span>
---

导致 HTML 输出,其中这些标签已被转义:

<h1 class="post-title p-name" itemprop="name headline">A post that says &lt;span lang=&quot;fr&quot;&gt;Bonjour&lt;/span&gt; and &lt;span lang=&quot;es&quot;&gt;Hola&lt;/span&gt;</h1>

我正在使用 Jekyll minima 主题。

因此,在 page.title 上根据设计设置的 minima theme of Jekyll, that you are using, there is an escape 过滤器。

来自文档:

Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn’t change strings that don’t have anything to escape.

来源:https://shopify.github.io/liquid/filters/escape/

如果您希望 span 显示,您应该编辑文件 _layouts/post.html 并删除此 espace 过滤器。

此文件的第 7 行应如下所示

    <h1 class="post-title p-name" itemprop="name headline">{{ page.title | escape }}</h1>

来源:https://github.com/jekyll/minima/blob/49f6dce0727a2441f0b0c265b41b5efc7b042eb6/_layouts/post.html#L7

将其更改为

    <h1 class="post-title p-name" itemprop="name headline">{{ page.title }}</h1>

您将获得预期的行为。