"对于具有编号标题的Jekyll帖子,"没有将Integer隐式转换为字符串"错误

Ker*_*rim 7 github liquid jekyll github-pages

我有一个哲基尔博客托管在GitHub上的页面我最近更新到HTTPS.在这样做的过程中,我发现最近对Jekyll的更新导致我的博客不再正常构建.运行本地安装我遇到以下错误:

Liquid Exception: no implicit conversion of Integer into String in /_layouts/default.html
Run Code Online (Sandbox Code Playgroud)

经过一些试验和错误,我能够确定以下帖子导致问题:

2003-09-21-100.md
2004-02-10-10000.md
2004-02-28-228.md
2004-09-10-1.md
2004-10-10-1969.md
2004-11-06-1896.md
2005-05-14-616.md
Run Code Online (Sandbox Code Playgroud)

这些都是我导入Jekyll的旧Wordpress帖子,正如你所看到的,它们都有数字作为标题.但是,它并没有在早期版本的Jekyll上造成构建问题.虽然我可以重命名所有这些旧帖子,但由于我不得不更新任何Disqus评论网址,而且网络上任何现有链接都会被破坏,因此会有点痛苦.有谁知道是否有更简单的方法来解决这个问题?谢谢!

mar*_*nuy 5

真正的问题是escape过滤器无法处理数字,例如:

{{ 1618 | escape }}
Run Code Online (Sandbox Code Playgroud)

抛出:

/tmp/vendor/ruby/2.3.0/gems/liquid-4.0.0/lib/liquid/standardfilters.rb:36:in `escapeHTML': no implicit conversion of Fixnum into Strin
g (TypeError)                  
Run Code Online (Sandbox Code Playgroud)

正如您escape在 titles:中使用的那样<title>{% if page.title %}{{ page.title | escape }}{% else %}{{ site.title | escape }}{% endif %}</title> ,许多标题只有数字,那么它就会失败。

一个快速修复它的方法是在使用escape过滤器之前使用capture变量标签将它们转换为字符串:

捕获开始和结束标记内的字符串并将其分配给变量。您使用捕获创建的变量存储为字符串。

_includes/head.html

{% capture mytitle%}{{page.title}}{%endcapture%}
<title>{% if mytitle %}{{ mytitle | escape }}{% else %}{{ site.title | escape }}{% endif %}</title>
Run Code Online (Sandbox Code Playgroud)