huntout.github.io

使用Jekyll与GitHub Pages构建网站

Jan 26, 2014

本博开篇,按例介绍一下使用 JekyllGitHub Pages 构建网站的流程,一为后来者造福,二为自己留个记录。

准备

我搭建的过程大部分也是乘着前人栽树的阴凉,下面是我建议的阅读清单

步骤

  • My OS: Windows 7 64 bits

  • Install Ruby 1.9

    Add C:\Ruby193\bin to Path

  • Install Ruby Development Kit for Ruby 1.9

    Extract it to C:\devkit

    C:\devkit>ruby dk.rb init
    C:\devkit>ruby dk.rb install
    C:\devkit>ruby -v
    ruby 1.9.3p484 (2013-11-22) [i386-mingw32]
    
  • Install Which and Wget for Windows

    Add C:\Program Files (x86)\GnuWin32\bin to Path

    C:\>which which
    C:\Program Files (x86)\GnuWin32\bin\which.EXE
    C:\>which wget
    C:\Program Files (x86)\GnuWin32\bin\wget.EXE
    
  • Install Python

    C:\temp>wget -nc python.org/ftp/python/2.7.2/python-2.7.2.msi
    C:\temp>msiexec -qn -i python-2.7.2.msi ADDLOCAL="DefaultFeature"
    

    Add C:\Python27 to Path

  • Install easy_install

    C:\temp>wget -nc peak.telecommunity.com/dist/ez_setup.py
    C:\temp>python ez_setup.py
    

    Add C:\Python27\Scripts to Path

  • Install Pygments

    C:\>easy_install Pygments
    
    --- C:\Ruby193\lib\ruby\gems\1.9.1\gems\pygments.rb-0.5.4\lib\pygments\popen.rb
    +++ C:\Ruby193\lib\ruby\gems\1.9.1\gems\pygments.rb-0.5.4\lib\pygments\popen.rb (Unsaved)
    @@ -46,8 +46,8 @@
     # something like that.
     def python_binary
       @python_binary ||= begin
    -        `which python2`
    -        $?.success? ? "python2" : "python"
    +        `which python`
    +        $?.success? ? "python" : "python2"
       end
     end
    
  • Install bundler

    C:\>gem install bundler
    
  • Create your Github Pages repository

    • Fork rsms.github.com
    • Rename repository to yourname.github.io
    • Edit CNAME to match your domain
  • Clone yourname.github.io to locale

    C:\>git clone git@github.com:yourname/yourname.github.io.git
    

    由于 GitHub Pages 不支持自定义 plugins,我采用了 generator-jekyllrb。源文件在 yo 分支,使用 Grunt 自动编译发布到 master 分支。(Updated on Feb 05, 2014)

  • Bundle

    C:\yourname.github.io>bundle install
    C:\yourname.github.io>bundle exec jekyll serve --watch
    
  • if you meet error: Invalid argument - C:/yourname.github.io/_site/C:.

    --- C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.4.3\lib\jekyll\page.rb
    +++ C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.4.3\lib\jekyll\page.rb (Unsaved)
    @@ -133,7 +133,7 @@
     #
     # Returns the destination file path String.
     def destination(dest)
    -      path = File.join(dest, File.expand_path(self.url, "/"))
    +      path = File.join(dest, self.url)
       path = File.join(path, "index.html") if self.url =~ /\/$/
       path
     end
    
    --- C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.4.3\lib\jekyll\post.rb
    +++ C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.4.3\lib\jekyll\post.rb (Unsaved)
    @@ -266,7 +266,7 @@
     # Returns destination file path String.
     def destination(dest)
       # The url needs to be unescaped in order to preserve the correct filename
    -      path = File.join(dest, File.expand_path(CGI.unescape(self.url), "/"))
    +      path = File.join(dest, CGI.unescape(self.url))
       path = File.join(path, "index.html") if path[/\.html$/].nil?
       path
     end
    

Enjoy it!