jekyll and github.io搭建博客遇到的问题

在windows下安装jekyll

原本看在windows下安装麻烦,所以在ubuntu下使用jekyll,安装只需一条sudo apt-get install。但是每次都要打开虚拟机感觉很不方便,虚拟机用起来有的时候也有些卡顿。所以还是打算在win下配置一下jekyll。
对此我本来毫无了解,起初按照简书上的一个教程来做(链接:在windows下安装jekyll),无非三步:1.安装 Ruby 2.安装 DevKit 3.安装 Jekyll,下面讲讲遇到的问题。
①Ruby官网地址:http://rubyinstaller.org/downloads/下载的时候完全没有进度,从0%开始卡住,所以不得不从别处找了installer(后来发现貌似除了部分版本外其他的速度还可以接受?)
②执行gem install jektll的时候报错,有乱码,也看不懂,查吧。

C:User>gem install jekyll
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing jekyll:
    ERROR: Failed to build gem native extension.

    current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20180308-3672-ueo7ea.rb extconf.rb
creating Makefile

current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
 make "DESTDIR=" clean
 'make' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���

current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR="
'make' �����ڲ����ⲿ���Ҳ���ǿ����еij���
 ���������ļ���

 make failed, exit code 1

Gem files will remain installed in C:/Ruby24-x64/bin/ruby_builtin_dlls/Ruby24-x6
4/lib/ruby/gems/2.4.0/gems/http_parser.rb-0.6.0 for inspection.
Results logged to C:/Ruby24-x64/bin/ruby_builtin_dlls/Ruby24-x64/lib/ruby/gems/2
.4.0/extensions/x64-mingw32/2.4.0/http_parser.rb-0.6.0/gem_make.out

花了蛮久时间找到了解决方案。作者也是参考了oneclick/rubyinstaller2的 issue #98 
③按照②中的解决方案,在cmd中输入下面命令来安装msys2:

$ ridk install

结果慢就算了,主要是每次都会

error: failed retrieving file 'xxx.db' from [url]

想想还是要换个镜像源,百度到了—给 MSYS2 添加中科大的源,照着换了源,再安装问题解决。

jekyll无法本地预览中文文件

提交了一片博客想本地预览,结果无法查看。凭经验感觉是md中文命名的缘故,查了一下果然如此,而据说提交到github上却可以正常解析。
找到的一个方法是: 修改安装目录Ruby22-x64lib uby2.2.0webrickhttpservlet下的filehandler.rb文件,建议先备份。 找到下列两处,添加一句(+的一行为添加部分)

1.

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

2.

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

修改完重新jekyll serve即可支持中文文件名。 
看起来可靠,没有尝试,毕竟英文命名也不费劲。

关于图片无法显示的一个问题

本地测试的时候显示正常,在gitpage上图片损坏,然而图片文件已经完好上传。

后来发现.md文件里引用用的是xxx.png,而文件本身是xxx.PNG——格式名大小写不一样。

但是这个问题不会在本地暴露出来,可能是gitpage的问题。

调试时,页面修改不能反映

这是因为浏览器(chrome)缓存的缘故。
1.可以在调试前清除浏览器缓存,或ctrl+shift+delete。
2.强制刷新页面,使用ctrl+shift+r强制刷新,不使用浏览器缓存来刷新页面。
3.也可以设置浏览器,在调试页面中勾选Disable cache。

原文地址:https://www.cnblogs.com/JK-Z/p/12262024.html