It's our wits that make us men.

解决jekyll无法本地预览中文文件的问题

Posted on By ZY
个人分类:jekyll

前言

  最近在使用jekyll在本地预览自己写的博客无法正常打开,而提交到github上却可以正常解析。看了一下发现是文件写的博客有什么变化, 原来是因为博客的markdown文件使用了中文文件名,jekyll无法正常解析导致出现乱码。

解决方法:

修改安装目录\Ruby25-x64\lib\ruby\2.5.0\webrick\httpservlet下的filehandler.rb文件,建议先备份。

找到下列两处,添加一句(+的一行为添加部分)

第一处修改部分:

path = req.path_info.dup.force_encoding(Encoding.find("filesystem"))
+ path.force_encoding("UTF-8") # 加入编码
if trailing_pathsep?(req.path_info)

第二处修改部分:

break if base == "/"
+ base.force_encoding("UTF-8") #加入编码
break unless File.directory?(File.expand_path(res.filename + base))



上一篇: 测试