jekyll本地環境搭建(Windows)

序:最近一直在搞Github建站,因此一直沒機會寫文章,那邊的環境雖然搞好了,可是網站的界面倒是個問題,不想用別人的,總想本身設計個,卻感受沒經驗吧,就一直耽擱了。因此也就沒心情在那邊寫文章,好久沒寫了,悶得很,一直沒機會把建站的過程總結分享下,今天忽然興起,仍是來這裏寫寫吧~html

 

PS:本人通常使用win xp,因此下文都是針對 win xp系統的,通常狀況下對於win系列系統都是適用的。至於linux/unix系統,本人不多玩,有機會試試。linux

 

1、配置ruby環境windows

因爲jekyll是用ruby語言寫的一個靜態網頁生成工具,因此要搭建jekyll本地環境就須要先配置好ruby環境。ruby

1)去官網下載Ruby:https://www.ruby-lang.org/zh_cn/downloads/,能夠是安裝包類型,也能夠是解壓版的。markdown

2)若是是安裝版,則默認會給你配置系統環境變量,若是是解壓版的,則須要本身配置系統環境變量。雖然本人喜歡解壓版的,但因爲本人功力還不夠,發現解壓版的缺乏不少必要的東東,無奈只能罷了。(固然若是必定要解壓版的,就把別人安裝好的拷過來吧!)網絡

3)鑑於本人是初學者吧,並且官方推薦不知道如何安裝的,就選擇RubyInstaller(這種安裝方式除 Ruby 以外,捆綁一些額外的資源庫。)。因此上面兩步就略過了,呵呵,下載了「rubyinstaller-1.9.3-p429.exe」,記得安裝的時候選上「Add Ruby executables to your PATH」(添加系統環境變量),我這裏安裝到了C:\Ruby下ide

4)下載DevKit,解壓進行執行相關命令(至於爲啥,我還不懂,這個是win系統下必要的步驟)。我解壓到了C:\devkit下,打開cmd,切換到C:\devkit下,分步執行以下紅色字樣命令,出現以下提示表示安裝成功了:工具

C:\>cd devkit

C:\devkit>ruby dk.rb init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby

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.

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

 

2、安裝jekyll(須要聯網安裝)post

打開cmd,執行以下紅色字樣命令(gem命令已在系統環境中,後面的jekyll亦如此),出現以下相似信息表示安裝成功(這裏會安裝jekyll所依賴的東西,因爲是聯網安裝,因此存在鏈接速度等網絡問題,若是出現錯誤,在確認前面安裝步驟正常的狀況下請多嘗試,耐心等待!!!過後添加[2013-10-08]:修改gem命令代碼源爲ruby.taobao.org速度應該會較快的,具體設置見:http://ruby.taobao.org/):網站

C:\>gem install jekyll
Fetching: liquid-2.5.2.gem (100%)
Fetching: fast-stemmer-1.0.2.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: classifier-1.3.3.gem (100%)
Fetching: directory_watcher-1.4.1.gem (100%)
Fetching: syntax-1.0.0.gem (100%)
Fetching: maruku-0.6.1.gem (100%)
Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%)
Fetching: posix-spawn-0.3.6.gem (100%)
Building native extensions.  This could take a while...
Fetching: pygments.rb-0.5.2.gem (100%)
Fetching: highline-1.6.19.gem (100%)
Fetching: commander-4.1.5.gem (100%)
Fetching: safe_yaml-0.7.1.gem (100%)
Fetching: colorator-0.1.gem (100%)
Fetching: redcarpet-2.2.2.gem (100%)
Building native extensions.  This could take a while...
Fetching: jekyll-1.2.0.gem (100%)
Successfully installed liquid-2.5.2
Successfully installed fast-stemmer-1.0.2
Successfully installed classifier-1.3.3
Successfully installed directory_watcher-1.4.1
Successfully installed syntax-1.0.0
Successfully installed maruku-0.6.1
Successfully installed yajl-ruby-1.1.0-x86-mingw32
Successfully installed posix-spawn-0.3.6
Successfully installed pygments.rb-0.5.2
Successfully installed highline-1.6.19
Successfully installed commander-4.1.5
Successfully installed safe_yaml-0.7.1
Successfully installed colorator-0.1
Successfully installed redcarpet-2.2.2
Successfully installed jekyll-1.2.0
15 gems installed
Installing ri documentation for liquid-2.5.2...
Installing ri documentation for fast-stemmer-1.0.2...
Installing ri documentation for classifier-1.3.3...
Installing ri documentation for directory_watcher-1.4.1...
Installing ri documentation for syntax-1.0.0...
Installing ri documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing ri documentation for posix-spawn-0.3.6...
Installing ri documentation for pygments.rb-0.5.2...
Installing ri documentation for highline-1.6.19...
Installing ri documentation for commander-4.1.5...
Installing ri documentation for safe_yaml-0.7.1...
Installing ri documentation for colorator-0.1...
Installing ri documentation for redcarpet-2.2.2...
Installing ri documentation for jekyll-1.2.0...
Installing RDoc documentation for liquid-2.5.2...
Installing RDoc documentation for fast-stemmer-1.0.2...
Installing RDoc documentation for classifier-1.3.3...
Installing RDoc documentation for directory_watcher-1.4.1...
Installing RDoc documentation for syntax-1.0.0...
Installing RDoc documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing RDoc documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing RDoc documentation for posix-spawn-0.3.6...
Installing RDoc documentation for pygments.rb-0.5.2...
Installing RDoc documentation for highline-1.6.19...
Installing RDoc documentation for commander-4.1.5...
Installing RDoc documentation for safe_yaml-0.7.1...
Installing RDoc documentation for colorator-0.1...
Installing RDoc documentation for redcarpet-2.2.2...
Installing RDoc documentation for jekyll-1.2.0...

C:\>jekyll -v
jekyll 1.2.0

 

3、使用jekyll建立網站並運行

jekyll是一個靜態網頁生成工具,那麼必然有所謂的「源碼」,或者說jekyll能夠把你寫的有必定格式的文件轉換成靜態網頁。經過jekyll -h查看幫助能夠發現有new參數,讓jekyll幫助建立一個網站,即在cmd中執行「jekyll new 網站名」便可,jekyll會在當前目錄下新建一個以網站名爲名的文件夾,裏面的是自動生成的一個簡單的網站內容。

爲了可以讓這裏網站正常運行,這裏須要刪除_post文件夾裏的文件(應該有一個xxxx-xx-xx-welcome-to-jekyll.markdown字樣的文件),由於這個文件內部使用了語法高亮插件(另外不刪,則能夠修改配置文件禁用該語法高亮插件,即修改根目錄下_config.yml中的pygments: true爲false即可。),這個須要另外安裝,再也不本文範圍內,不刪會致使生成的靜態頁面有問題,因時間有限本文暫不提此問題。

另外還會存在編碼上的問題,但如今只要不在裏面用中文,就暫時沒事,後面文章再提。

最後切換到新建的網站目錄下,執行jekyll serve來啓動網站,默認生成的靜態網頁等相關資源會放入_site文件夾。命令執行結果以下:

C:\testjekyll>jekyll serve
Configuration file: C:/testjekyll/_config.yml
            Source: C:/testjekyll
       Destination: C:/testjekyll/_site
      Generating... done.
[2013-09-08 17:34:51] INFO  WEBrick 1.3.1
[2013-09-08 17:34:51] INFO  ruby 1.9.3 (2013-05-15) [i386-mingw32]
[2013-09-08 17:34:51] INFO  WEBrick::HTTPServer#start: pid=984 port=4000

如上可見配置文件是_config.yml,網站的端口是4000,經過http://localhost:4000來訪問便可。

 

PS:以上安裝完後,就能夠自由拷貝到別的同類系統中配置並運行了(jekyll是被安裝在Ruby目錄下),網上有外國網友分享了此類東東,不過外國的東東多少跟咱們有些出入,有興趣的朋友能夠試試(我暫時還沒試過)。

 

參考資料:

http://www.madhur.co.in/blog/2011/09/01/runningjekyllwindows.html

http://jekyllrb.com/

相關文章
相關標籤/搜索