Jekyll:某些变量的液体过滤器 "cgi_escape" returns 错误

Jekyll: Liquid filter "cgi_escape" returns error for some variables

简短版本:您是否设法在 {% include %} 部分中使用了类似 {{ page.title | cgi_escape }} 的内容?

详情如下:

我有一部分是这样使用的:

{% include mainContainer.html %}

工作正常。然后,在该部分中,尝试显示一些液体变量:

{{ page.title }} 显示标题。

{{ page.content }} 显示内容。

{{ page.content | cgi_escape }} 显示内容,但转义了。

{{ page.title | cgi_escape }} 根本不起作用。产生以下错误:

Liquid Exception: undefined method `encoding' for nil:NilClass 

除了 {{ page.content }} 之外,我得到任何 {{ page }} 变量(类别、标题等)的错误,但所有这些都将正常显示 而没有 过滤器。此外,{{ page.title | cgi_escape }} 在布局的...呃...'content' 部分工作正常(我不确定如何称呼它 - {{ content }} 部分)。我似乎只收到 {% include %}

的错误

没关系。构建失败是因为一些使用 {% include mainContainer.html %} 的页面没有任何 front matter,因此没有 page.title(或其他)。显然,如果未设置变量,Liquid 愿意让 {{ page.title }} 通过,但不会 {{ page.title | cgi_encode }}