一般编写都是采用utf-8的吧,但是在windows下安装的jekyll,默认是以GBK编码的方式去读取咱们编写的文件,如此便乱码了。

要解决此问题,总不至于要写GBK编码的文件吧,毕竟这个编码不怎么通用,所以需要修改jekyll中的代码,让其以utf-8编码来读取我们的文件,已有网友找到解决方法!需要修改jekyll中读取的代码,指定为utf-8编码即可。具体如下:

错误信息:

   Generating... Error reading file e:/xampp/htdocs/ieverx/ieverx/_posts/
---logic-operation-in-python.md:
invalid byte sequence in GBK
error: invalid byte sequence in GBK. Use --trace to view backtrace

修改方法:

/文件:C:\Ruby200\lib\ruby\gems\2.0.0\gems\jekyll-1.2.1\lib\jekyll
//具体路径视版本号及安装路径有所不同
//找到如下代码:
self.content = File.read(File.join(base, name))
//修改为:
self.content = File.read(File.join(base, name), :encoding => "utf-8")

之后在文件中写入中文时,记得保存为utf-8的编码,否则运行时会报错的哦!

事后(2013-09-20),在C:\Ruby200\lib\ruby\gems\2.0.0\gems\jekyll-1.2.1\site中发现疑似jekyll官网源码,且是以jekyll来运行的,于是好奇考出执行jekyll serve命令,谁知报如下错误:

初步推测是编码问题,此时前面提到的编码问题已经修复,定是其它地方出现此类问题导致。通过jekyll serve --trace命令打印出详细错误信息:

from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/template.rb:169:in `tokenize'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/template.rb:75:in `parse'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/template.rb:62:in `parse'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/tags/include.rb:59:in `render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/block.rb:137:in `block in render_all'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/block.rb:124:in `each'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/block.rb:124:in `render_all'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/block.rb:110:in `render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/template.rb:150:in `render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/liquid-2.5.2/lib/liquid/template.rb:160:in `render!'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/convertible.rb:82:in `render_liquid'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/convertible.rb:113:in `render_all_layouts'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/convertible.rb:148:in `do_layout'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/post.rb:259:in `render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/site.rb:205:in `block in render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/site.rb:204:in `each'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/site.rb:204:in `render'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/site.rb:36:in `process'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/command.rb:18:in `process_site'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/commands/build.rb:23:in `build'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/lib/jekyll/commands/build.rb:7:in `process'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/jekyll-1.2.1/bin/jekyll:99:in `block (2 levels) in <top (required)>'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/command.rb:180:in `call'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/command.rb:180:in `call'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/command.rb:155:in `run'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:402:in `run_active_command'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/runner.rb:78:in `run!'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/delegates.rb:11:in `run!'
from C://Ruby200/lib/ruby/gems/2.0.0/gems/commander-4.1.5/lib/commander/import.rb:10:in `block in <top (required)>'

之后一个个文件查看了下,发现C:\Ruby200\lib\ruby\gems\2.0.0\gems\jekyll-1.2.1\lib\jekyll\tags\include.rb中有有文件读取代码,经如下修改能正常运行:

#原来的代码
source = File.read(File.join(includes_dir, @file)) #修改为以utf-8编码读取
source = File.read(File.join(includes_dir, @file),:encoding=>"utf-8")

编码问题解决之后!
继续

jekyll server

接着出现的问题

      Generating... You are missing a library required for Markdown. Please run:

  $ [sudo] gem install kramdown
Conversion error: There was an error converting '_posts/2012-06-20-logic-opera
tion-in-python.md/#excerpt'. ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Missing dependency: kramdown

则直接输入

gem install kramdown

全部完成!

04-30 05:10