尝试运行jekyll build
或jekyll serve
时出现以下错误:
Liquid Exception: undefined method 'encoding' for nil:NilClass in _layouts/post.html
jekyll 2.5.3 | Error: undefined method 'encoding' for nil:NilClass
看起来是RVM / ruby文件的问题? (请参阅下面的--trace日志)但我并没有真正触及任何代码(特别是在任何ruby文件中)并且没有编辑过' / _ layouts / post.html'在最后几次提交中,这只是刚刚出现。
这里是Github上的存储库:https://github.com/ryanstraits/ryanstraits.github.io,虽然主分支在发生此错误之前的最后一次提交。
没有太多严肃的程序员,所以我有点困惑。任何帮助都会很棒。
这是我运行jekyll build --trace
时得到的结果:
Liquid Exception: undefined method encoding' for nil:NilClass in _layouts/post.html /Users/Straits/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/cgi/util.rb:8:inescape': undefined method encoding' for nil:NilClass (NoMethodError) from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/filters.rb:134:incgi_escape'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/strainer.rb:43:in invoke' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/context.rb:82:ininvoke'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/variable.rb:50:in block in render' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/variable.rb:38:ineach'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/variable.rb:38:in inject' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/variable.rb:38:inrender'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:109:in block in render_all' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:ineach'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in render_all' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/if.rb:40:inblock (2 levels) in render'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/if.rb:38:in each' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/if.rb:38:inblock in render'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/context.rb:112:in stack' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/if.rb:37:inrender'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:109:in block in render_all' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:ineach'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in render_all' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/for.rb:117:inblock (2 levels) in render'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/for.rb:105:in each' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/for.rb:105:ineach_with_index'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/for.rb:105:in block in render' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/context.rb:112:instack'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/tags/for.rb:104:in render' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:109:inblock in render_all'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:in each' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:96:inrender_all'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/block.rb:82:in render' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/template.rb:128:inrender'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/liquid-2.6.2/lib/liquid/template.rb:138:in render!' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:106:inrender_liquid'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:205:in render_all_layouts' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/convertible.rb:239:indo_layout'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/post.rb:261:in render' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:298:inblock in render'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:in each' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:297:inrender'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/site.rb:51:in process' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/command.rb:28:inprocess_site'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:56:in build' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:34:inprocess'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/lib/jekyll/commands/build.rb:18:in block (2 levels) in init_with_program' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:incall'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in block in execute' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:ineach'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in execute' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:ingo'
from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/mercenary-0.3.5/lib/mercenary.rb:19:in program' from /Users/Straits/.rvm/gems/ruby-2.2.0/gems/jekyll-2.5.3/bin/jekyll:20:in'
from /Users/Straits/.rvm/gems/ruby-2.2.0/bin/jekyll:23:in load' from /Users/Straits/.rvm/gems/ruby-2.2.0/bin/jekyll:23:in
'
from /Users/Straits/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in eval' from /Users/Straits/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in'
答案 0 :(得分:3)
对我来说问题是:
{{ cgi_escape_title = page.title | cgi_escape }}
我的_layouts/default.html
中的适用于没有page.title
的网页。
一种解决方案是:
{{ page.title | default: "" | cgi_escape }}
将nul
标题转换为""
,或者如果您感觉更加冗长:
{% if page.title %}
{% assign cgi_escape_title = page.title | cgi_escape %}
{% else %}
{% assign cgi_escape_title = '' %}
{% endif %}
{{ cgi_escape_title }}
在Jekyll 3.0.3上测试。
答案 1 :(得分:1)
发现问题:我的很多帖子是使用" Wordpress导入到Jekyll"转换器,看起来它离开了"标题:"在这些帖子的前面几个字段中的字段空白。只是希望错误更加具体。
我想在一天结束时的教训是:不要让你的前方问题留空,伙计们!