Home Archives Categories Tags

使用Jekyll在Github上搭建博客 – 环境安装

发布时间: 更新时间: 总字数:3760 阅读时间:8m 作者: 分享

本博客主要介绍如何安装Jekyll + github博客开发环境。

什么是Jekyll+github

Git官网首页(http://jekyllrb.com/)上的描述说: Transform your plain text into static websites and blogs。

Jekyll将原始文本根据一定规则转换成静态的网页和博客。但这个转换并不是简单的字符串替换就了事了,而是首先读取各个文件中的内容,根据配置文件中描述的参数在内存中构建一个巨大的对象存储整个博客的信息,然后再将这些信息根据配置文件中定义的输出方式来生成具体的HTML文件。整个项目是由Ruby写的,所以若需要在本地调试则需要安装Ruby。

使用Jekyll搭建博客有几个好处:

  • 不需要使用额外的数据库
  • 支持markdown,liquid,以及原始的html、css
  • 可以定义模板,并在模板上进行代码复用
  • github对其支持,可以直接在github上搭建,可以继承github上的各种好处(版本控制,免费,无流量限制)
  • 有很多扩展插件(但是在github上用不了,github不允许用户使用扩展插件,大概是出于安全性考虑)


当然缺点也有很多:

  • 生成的是静态网页,无法动态加载,若需要外部服务如评论,只能使用类似于disquz,多说这样的外部插件了
  • 仅仅适合小型网站,不适合大中型网站
  • 没有数据库及服务端的逻辑

由此可见,用来搭建个人博客相当合适(github版本控制,免费,无流量限制,支持markdown,无需关心服务器端逻辑和数据库)

本地安装Jekyll

安装Ruby

从RubyInstaller(http://rubyinstaller.org/)下载ruby,如果有经验的可以直接从Ruby官网进行下载,前者安装比较无脑,会有一些额外的依赖包进行安装,版本也较低,而Ruby官网的版本则相对较高,但是没有额外的依赖包。下载的时候版本选较高一些的,否则会有bug,我选择的是Ruby 2.1.7 (x64)(http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.1.7-x64.exe)。安装的时候记得勾选添加环境变量。

安装devkit

RubyInstaller页面中往下拉就能看到。我下载的是:http://dl.bintray.com/oneclick/rubyinstaller/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe。

进入devkit的解压目录,依次执行如下命令:

初始化config.yml:

C:\devkit>ruby dk.rb init

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

修改刚生产的config.yml文件,添加ruby的根目录,如下:

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
- C:\Ruby21-x64

安装devkit:

C:\devkit>ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby21-x64'
[INFO] Installing 'C:/Ruby21-x64/lib/ruby/site_ruby/devkit.rb'

至此,完成ruby环境的安装。

安装gem

到去gem官网(http://rubygems.org/)进行下载,然后直接安装就行了,安装完成后使用gem -v查看一下是否安装成功。我安装的是2.4.8版本:

进入,解压目录:

D:\rubygems-2.4.8>ruby setup.rb install
RubyGems 2.4.8 installed
Parsing documentation for rubygems-2.4.8
Installing ri documentation for rubygems-2.4.8

=== 2.4.8 / 2015-06-08

Bug fixes:

* Tightened API endpoint checks for CVE-2015-3900

=== 2.4.7 / 2015-05-14

Bug fixes:

* Backport: Limit API endpoint to original security domain for CVE-2015-3900.
  Fix by claudijd

=== 2.4.6 / 2014-02-05

Bug fixes:

* Fixed resolving gems with both upper and lower requirement boundaries.
  Issue #1141 by Jakub Jirutka.
* Moved extension directory after require_paths to fix missing constant bugs
  in some gems with C extensions.  Issue #784 by André Arko, pull request
  #1137 by Barry Allard.
* Use Gem::Dependency#requirement when adding a dependency to an existing
  dependency instance.  Pull request #1101 by Josh Cheek.
* Fixed warning of shadowed local variable in Gem::Specification.  Pull request
  #1109 by Rohit Arondekar
* Gem::Requirement should always sort requirements before coercion to Hash.
  Pull request #1139 by Eito Katagiri.
* The `gem open` command should change the current working directory before
  opening the editor.  Pull request #1142 by Alex Wood.
* Ensure quotes are stripped from the Windows launcher script used to install
  gems.  Pull request #1115 by Youngjun Song.
* Fixed errors when writing to NFS to to 0444 files.  Issue #1161 by Emmanuel
  Hadoux.
* Removed dead code in Gem::StreamUI.  Pull request #1117 by mediaslave24.
* Fixed typos.  Pull request #1096 by hakeda.
* Relaxed CMake dependency for RHEL 6 and CentOS 6.  Pull request #1124 by Vít
  Ondruch.
* Relaxed Psych dependency.  Pull request #1128 by Vít Ondruch.

=== 2.4.5 / 2014-12-03

Bug fixes:

* Improved speed of requiring gems.  (Around 25% for a 60 gem test).  Pull
  request #1060 by unak.
* RubyGems no longer attempts to look up gems remotely with the --local flag.
  Pull request #1084 by Jeremy Evans.
* Executable stubs use the correct gem version when RUBYGEMS_GEMDEPS is
  active.  Issue #1072 by Michael Kaiser-Nyman.
* Fixed handling of pinned gems in lockfiles with versions.  Issue #1078 by
  Ian Ker-Seymer.
* Fixed handling of git@example:gem.git URIs.  Issue #1054 by Mogutan Mogu.
* Fixed handling of platforms retrieved from the dependencies API.  Issue
  #1058 and patch suggestion by tux-mind.
* RubyGems now suggests a copy-pasteable `gem pristine` command when
  extensions are missing.  Pull request #1057 by Shannon Skipper.
* Improved errors for long file names when packaging.  Pull request #1016 by
  Piotrek Bator.
* `gem pristine` now skips gems cannot be found remotely.  Pull request #1064
  by Tuomas Kareinen.
* `gem pristine` now caches gems to the proper directory.  Pull request #1064
  by Tuomas Kareinen.
* `gem pristine` now skips bundled gems properly.  Pull request #1064 by
  Tuomas Kareinen.
* Improved interoperability of Vagrant with RubyGems.  Pull request #1057 by
  Vít Ondruch.
* Renamed CONTRIBUTING to CONTRIBUTING.rdoc to allow markup.  Pull request
  #1090 by Roberto Miranda.
* Switched from #partition to #reject as only one collection is used.  Pull
  request #1074 by Tuomas Kareinen.
* Fixed installation of gems on systems using memory-mapped files.  Pull
  request #1038 by Justin Li.
* Fixed bug in Gem::Text#min3 where `a == b < c`.  Pull request #1026 by
  fortissimo1997.
* Fixed uninitialized variable warning in BasicSpecification.  Pull request
  #1019 by Piotr Szotkowski.
* Removed unneeded exception handling for cyclic dependencies.  Pull request
  #1043 by Jens Wille.
* Fixed grouped expression warning.  Pull request #1081 by André Arko.
* Fixed handling of platforms when writing lockfiles.

=== 2.4.4 / 2014-11-12

Bug fixes:

* Add alternate Root CA for upcoming certificate change. Fixes #1050 by
  Protosac

=== 2.4.3 / 2014-11-10

Bug fixes:

* Fix redefine MirrorCommand issue. Pull request #1044 by @akr.
* Fix typo in platform= docs.  Pull request #1048 by @jasonrclark
* Add root SSL certificates for upcoming certificate change.  Fixes #1050 by
  Protosac

=== 2.4.2 / 2014-10-01

This release was sponsored by Ruby Central.

Bug fixes:

* RubyGems now correctly matches wildcard no_proxy hosts.  Issue #997 by
  voelzemo.
* Added support for missing git_source method in the gem dependencies API.
* Fixed handling of git gems with an alternate install directory.
* Lockfiles will no longer be truncated upon resolution errors.
* Fixed messaging for `gem owner -a`.  Issue #1004 by Aaron Patterson, Ryan
  Davis.
* Removed meaningless ensure.  Pull request #1003 by gogotanaka.
* Improved wording of --source option help.  Pull request #989 by Jason Clark.
* Empty build_info files are now ignored.  Issue #903 by Adan Alvarado.
* Gem::Installer ignores dependency checks when installing development
  dependencies.  Issue #994 by Jens Willie.
* `gem update` now continues after dependency errors.  Issue #993 by aaronchi.
* RubyGems no longer warns about semantic version dependencies for the 0.x
  range.  Issue #987 by Jeff Felchner, pull request #1006 by Hsing-Hui Hsu.
* Added minimal lock to allow multithread installation of gems.  Issue #982
  and pull request #1005 by Yorick Peterse
* RubyGems now considers prerelease dependencies as it did in earlier versions
  when --prerelease is given.  Issue #990 by Jeremy Tryba.
* Updated capitalization in README.  Issue #1010 by Ben Bodenmiller.
* Fixed activating gems from a Gemfile for default gems.  Issue #991 by khoan.
* Fixed windows stub script generation for Cygwin.  Issue #1000 by Brett
  DiFrischia.
* Allow gem bindir and ruby.exe to live in separate diretories.  Pull request
  #942 by Ian Flynn.
* Fixed handling of gemspec in gem dependencies files to match Bundler
  behavior.  Issue #1020 by Michal Papis.
* Fixed `gem update` when updating to prereleases.  Issue #1028 by Santiago
  Pastorino.
* RubyGems now fails immediately when a git reference cannot be found instead
  of spewing git errors.  Issue #1031 by Michal Papis

=== 2.4.1 / 2014-07-17

Bug fixes:

* RubyGems can now be updated on Ruby implementations that do not support
  vendordir in RbConfig::CONFIG.  Issue #974 by net1957.

=== 2.4.0 / 2014-07-16

Minor enhancements:

* The contents command now supports a --show-install-dir option that shows
  only the directory the gem is installed in.  Feature request #966 by Akinori
  MUSHA.
* Added a --build-root option to the install command for packagers.  Pull
  request #965 by Marcus Rückert.
* Added vendor gem support to RubyGems.  Package managers may now install gems
  in Gem.vendor_dir with the --vendor option to gem install.  Issue #943 by
  Marcus Rückert.

Bug fixes:

* Kernel#gem now respects the prerelease flag when activating gems.
  Previously this behavior was undefined which could lead to bugs when a
  prerelease version was unintentionally activated.  Bug #938 by Joe Ferris.
* RubyGems now prefers gems from git over installed gems.  This allows gems
  from git to override an installed gem with the same name and version.  Bug
  #944 by Thomas Kriechbaumer.
* Fixed handling of git gems in a lockfile with unversioned dependencies.  Bug
  #940 by Michael Kaiser-Nyman.
* The ruby directive in a gem dependencies file is ignored when installing.
  Bug #941 by Michael Kaiser-Nyman.
* Added open to list of builtin commands (`gem open` now works).  Reported by
  Espen Antonsen.
* `gem open` now works with command-line editors.  Pull request #962 by Tim
  Pope.
* `gem install -g` now respects `--conservative`.  Pull request #950 by Jeremy
  Evans.
* RubyGems releases announcements now now include checksums.  Bug #939 by
  Alexander E. Fischer.
* RubyGems now expands ~ in $PATH when checking if installed executables will
  be runnable.  Pull request #945 by Alex Talker.
* Fixed `gem install -g --explain`.  Issue #947 by Luis Lavena.  Patch by
  Hsing-Hui Hsu.
* RubyGems locks less during gem activation.  Pull request #951 by Aaron
  Patterson and Justin Searls, #969 by Jeremy Tryba.
* Kernel#gem is now thread-safe.  Pull request #967 by Aaron Patterson.
* RubyGems now handles spaces in directory names for some parts of extension
  building.  Pull request #949 by Tristan Hill.
* RubyGems no longer defines an empty Date class.  Pull Request #948 by Benoit
  Daloze.
* RubyGems respects --document options for `gem update` again.  Bug 946 by
  jonforums.  Patch by Hsing-Hui Hsu.
* RubyGems generates documentation again with --ignore-dependencies.  Bug #961
  by Pulfer.
* RubyGems can install extensions across partitions now.  Pull request #970 by
  Michael Scherer.
* `-s` is now short for `--source` which resolves an ambiguity with
  --no-suggestions.  Pull request #955 by Alexander Kahn.
* Added extra test for ~> for 0.0.X versions.  Pull request #958 by Mark
  Lorenz.
* Fixed typo in gem updated help.  Pull request #952 by Per Modin.
* Clarified that the gem description should not be excessively long.  Part of
  bug #956 by Renier Morales.
* Hid documentation of outdated test_files related methods in Specification.
  Guides issue #90 by Emil Soman.
* RubyGems now falls back to the old index if the rubygems.org API fails
  during gem resolution.



------------------------------------------------------------------------------

RubyGems installed the following executables:
        C:/Ruby21-x64/bin/gem

Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for ruby libraries. You may access it like this:
  ri Classname
  ri Classname.class_method
  ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.


D:\rubygems-2.4.8>

gem是可以选择源的,默认的源有点慢,可以使用ruby.taobao.org的源,方便快捷。操作如下:

查看当前源:

C:\Users\xiexianbin>gem sources list
*** CURRENT SOURCES ***

https://rubygems.org/

C:\Users\xiexianbin>

修改ruby新源:

C:\Users\xiexianbin>gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
https://ruby.taobao.org/ added to sources
https://rubygems.org/ removed from sources
或
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/

确保只有taobao的Ruby源:

C:\Users\xiexianbin>gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org/

再次查看的时候保证只有http://ruby.taobao.org/就行了

如果上面出错,去网上找找教程吧,ruby环境的搭建和gem的安装教程还是蛮多的,基本google一下遍地都是。

使用gem安装Jekyll

使用命令:

gem install jekyll

就可以安装jekyll及所有需要的依赖,但不包括插件,安装jekyll的时候需要注意一下安装的版问题,jekyll的最新版本为1.4.3,但是有一个bug,stackoverflow上有人遇到过,我自己在使用的时候也遇到了类似的问题,解决方法是安装1.4.2版本,所以这里的安装命令为:

C:\Users\xiexianbin>gem install jekyll --version "=1.4.2"
Fetching: blankslate-2.1.2.4.gem (100%)
Successfully installed blankslate-2.1.2.4
Fetching: parslet-1.5.0.gem (100%)
Successfully installed parslet-1.5.0
Fetching: toml-0.1.2.gem (100%)
Successfully installed toml-0.1.2
Fetching: redcarpet-2.3.0.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed redcarpet-2.3.0
Fetching: safe_yaml-0.9.7.gem (100%)
Successfully installed safe_yaml-0.9.7
Fetching: yajl-ruby-1.1.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed yajl-ruby-1.1.0
Fetching: posix-spawn-0.3.11.gem (100%)
Building native extensions.  This could take a while...
Successfully installed posix-spawn-0.3.11
Fetching: pygments.rb-0.5.4.gem (100%)
Successfully installed pygments.rb-0.5.4
Fetching: maruku-0.7.2.gem (100%)
Successfully installed maruku-0.7.2
Fetching: ffi-1.9.10-x64-mingw32.gem (100%)
Successfully installed ffi-1.9.10-x64-mingw32
Fetching: rb-kqueue-0.2.4.gem (100%)
Successfully installed rb-kqueue-0.2.4
Fetching: rb-inotify-0.9.5.gem (100%)
Successfully installed rb-inotify-0.9.5
Fetching: rb-fsevent-0.9.6.gem (100%)
Successfully installed rb-fsevent-0.9.6
Fetching: listen-1.3.1.gem (100%)
Successfully installed listen-1.3.1
Fetching: liquid-2.5.5.gem (100%)
Successfully installed liquid-2.5.5
Fetching: colorator-0.1.gem (100%)
Successfully installed colorator-0.1
Fetching: highline-1.6.21.gem (100%)
Successfully installed highline-1.6.21
Fetching: commander-4.1.6.gem (100%)
Successfully installed commander-4.1.6
Fetching: fast-stemmer-1.0.2.gem (100%)
Building native extensions.  This could take a while...
Successfully installed fast-stemmer-1.0.2
Fetching: classifier-1.3.4.gem (100%)
Successfully installed classifier-1.3.4
Fetching: jekyll-1.4.2.gem (100%)
Successfully installed jekyll-1.4.2
Parsing documentation for blankslate-2.1.2.4
Installing ri documentation for blankslate-2.1.2.4
Parsing documentation for parslet-1.5.0
Installing ri documentation for parslet-1.5.0
Parsing documentation for toml-0.1.2
Installing ri documentation for toml-0.1.2
Parsing documentation for redcarpet-2.3.0
Installing ri documentation for redcarpet-2.3.0
Parsing documentation for safe_yaml-0.9.7
Installing ri documentation for safe_yaml-0.9.7
Parsing documentation for yajl-ruby-1.1.0
Installing ri documentation for yajl-ruby-1.1.0
Parsing documentation for posix-spawn-0.3.11
Installing ri documentation for posix-spawn-0.3.11
Parsing documentation for pygments.rb-0.5.4
Installing ri documentation for pygments.rb-0.5.4
Parsing documentation for maruku-0.7.2
Installing ri documentation for maruku-0.7.2
Parsing documentation for ffi-1.9.10-x64-mingw32
Installing ri documentation for ffi-1.9.10-x64-mingw32
Parsing documentation for rb-kqueue-0.2.4
Installing ri documentation for rb-kqueue-0.2.4
Parsing documentation for rb-inotify-0.9.5
Installing ri documentation for rb-inotify-0.9.5
Parsing documentation for rb-fsevent-0.9.6
Installing ri documentation for rb-fsevent-0.9.6
Parsing documentation for listen-1.3.1
Installing ri documentation for listen-1.3.1
Parsing documentation for liquid-2.5.5
Installing ri documentation for liquid-2.5.5
Parsing documentation for colorator-0.1
Installing ri documentation for colorator-0.1
Parsing documentation for highline-1.6.21
Installing ri documentation for highline-1.6.21
Parsing documentation for commander-4.1.6
Installing ri documentation for commander-4.1.6
Parsing documentation for fast-stemmer-1.0.2
Installing ri documentation for fast-stemmer-1.0.2
Parsing documentation for classifier-1.3.4
Installing ri documentation for classifier-1.3.4
Parsing documentation for jekyll-1.4.2
Installing ri documentation for jekyll-1.4.2
Done installing documentation for blankslate, parslet, toml, redcarpet, safe_yam
l, yajl-ruby, posix-spawn, pygments.rb, maruku, ffi, rb-kqueue, rb-inotify, rb-f
sevent, listen, liquid, colorator, highline, commander, fast-stemmer, classifier
, jekyll after 75 seconds
21 gems installed

C:\Users\xiexianbin>

安装完成后使用jekyll -v查看一下是否安装成功:

C:\Users\xiexianbin>jekyll -v
jekyll 1.4.2

C:\Users\xiexianbin>

至此,Jekyll的安装成功。

生产页面

jekyll build

kramdown

D:\github\xiexianbin.github.io>gem install kramdown
Fetching: kramdown-1.9.0.gem (100%)
Successfully installed kramdown-1.9.0
Parsing documentation for kramdown-1.9.0
Installing ri documentation for kramdown-1.9.0
Done installing documentation for kramdown after 17 seconds
1 gem installed

测试安装

所有文档使用:utf-8无BOM格式。

D:\github\xiexianbin.github.io>jekyll server ./
Configuration file: D:/github/xiexianbin.github.io/_config.yml
            Source: D:/github/xiexianbin.github.io
       Destination: D:/github/xiexianbin.github.io/_site
      Generating... done.
    Server address: http://0.0.0.0:4000
  Server running... press ctrl-c to stop.

若有错误,请先执行:

chcp 65001

修改源:

bundle config mirror.https://rubygems.org https://ruby.taobao.org

完毕。

最新评论
加载中...