gpt4 book ai didi

github - 具有编号标题的 Jekyll 帖子出现 "no implicit conversion of Integer into String"错误

转载 作者:行者123 更新时间:2023-12-02 07:18:31 24 4
gpt4 key购买 nike

我有a Jekyll blog托管on GitHub Pages that我最近更新到了 HTTPS。在此过程中,我发现 Jekyll 最近的更新导致我的博客无法正常构建。运行本地安装时我不断遇到以下错误:

Liquid Exception: no implicit conversion of Integer into String in /_layouts/default.html

经过一番尝试和错误后,我能够确定以下帖子导致了问题:

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

这些都是我导入 Jekyll 的旧 WordPress 帖子,如您所见,它们都有数字作为标题。然而,它并没有在 Jekyll 的早期版本上造成构建问题。虽然我可以重命名所有这些旧帖子,但这会有点痛苦,因为我必须更新任何 Disqus 评论 URL,并且网络上指向这些帖子的任何现有链接都会被破坏。有谁知道是否有更简单的方法来解决这个问题?谢谢!

最佳答案

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

{{ 1618 | escape }}

抛出:

/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)

当您使用escape时在标题中:<title>{% if page.title %}{{ page.title | escape }}{% else %}{{ site.title | escape }}{% endif %}</title>而很多标题只有数字,那么它就会失败。

解决这个问题的一个快速技巧是在使用 escape 之前将它们转换为字符串。过滤器,使用 capture变量标签:

Captures the string inside of the opening and closing tags and assigns it to a variable. Variables that you create using capture are stored as strings.

_includes/head.html :

{% capture mytitle%}{{page.title}}{%endcapture%}
<title>{% if mytitle %}{{ mytitle | escape }}{% else %}{{ site.title | escape }}{% endif %}</title>

关于github - 具有编号标题的 Jekyll 帖子出现 "no implicit conversion of Integer into String"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45757708/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com