诡异的jekyll空格问题

近来考虑把博客迁移到Jekyll,折腾了一下相关的配置和安装方法。
 
今天就碰到了一个很诡异的问题。

现象

Jekyll Server启动后,_site目录中无法生成HTML。
 
浏览器显示的错误为:
ERROR no access permission to `/'
 
控制台日志如下:
[david@Atlantis jekll-base]$ jekyll --server 
/usr/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use String#encode instead.
Configuration from /home/david/temp/jekll-base/_config.yml
Auto-regenerating enabled: /home/david/temp/jekll-base -> /home/david/temp/jekll-base/_site
[2012-02-14 10:26:35] regeneration: 10 files changed
[2012-02-14 10:26:36] INFO WEBrick 1.3.1
[2012-02-14 10:26:36] INFO ruby 1.9.3 (2011-10-30) [i686-linux]
[2012-02-14 10:26:36] WARN TCPServer Error: Address already in use - bind(2)
[2012-02-14 10:26:36] INFO WEBrick::HTTPServer#start: pid=671 port=4000
[2012-02-14 10:27:33] ERROR no access permission to `/'

192.168.9.10 - - [14/Feb/2012:10:27:32 CST] "GET / HTTP/1.1" 403 285
- -> /
[2012-02-14 10:28:03] ERROR `/favicon.ico' not found.
192.168.9.10 - - [14/Feb/2012:10:28:03 CST] "GET /favicon.ico HTTP/1.1" 404 283
- -> /favicon.ico
^C[2012-02-14 10:29:49] INFO going to shutdown ...
[2012-02-14 10:29:49] INFO WEBrick::HTTPServer#start done.
[david@Atlantis jekll-base]$

分析

使用--no-auto查看jekyll启动过程,发现post.rb抛错。
[david@Atlantis jekll-base]$ jekyll --no-auto 
/usr/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': iconv will be deprecated in the future, use String#encode instead.
Configuration from /home/david/temp/jekll-base/_config.yml
Building site: /home/david/temp/jekll-base -> /home/david/temp/jekll-base/_site
/usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/post.rb:43:in `initialize'
: undefined method `has_key?' for "layout:post title:Test":String (NoMethodError)
        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:163:in `new'

        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:163:in `block in read_posts'
        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:161:in `each'

        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:161:in `read_posts'
        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:128:in `read_directories'

        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:98:in `read'
        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/lib/jekyll/site.rb:38:in `process'

        from /usr/lib/ruby/gems/1.9.1/gems/jekyll-0.11.2/bin/jekyll:250:in `<top (required)>'
        from /usr/bin/jekyll:19:in `load'

        from /usr/bin/jekyll:19:in `<main>'
忽然想起之前看过的一篇博客,这篇文章中提及“YAML格式默认是:参数+:+空格,如果忘记写空格描绘编译报错。”。
 
在这里,正是因为忘记了空格导致了HTML文件无法生成的问题。

解决办法

把_post目录中有关文件的YAML格式改为:参数+:+空格。
 
如下,问题解决。
[david@Atlantis _posts]$ head 2012-02-09-First-Post.md 
---
layout: post
title: First Post
---

In the beginning God created the heavens and the earth.




posted @ 2012-02-14 15:14  __BSD__  阅读(2130)  评论(0编辑  收藏