如何安裝jekyll並搭建一個博客

1. jekyll介紹

Jekyll是一個簡單的,博客感知的靜態站點生成器。
你將內容創建爲文本文件(Markdown),並將其放到到文件夾中。然後,使用Liquid-enhanced HTML模板構建網站。Jekyll自動將內容和模板聯繫在一起,生成完全由靜態資源組成的網站,它適合上傳到任何服務器。
Jekyll恰好是GitHub Pages的引擎,因此你可以在GitHub的服務器上免費託管項目的Jekyll頁面/博客/網站。

2. windows安裝

2.1 安裝 Ruby development environment.

2.2 安裝Jekyll and bundler gems.

# 移除gem默認源,改成ruby-china源
$ gem sources -r https://rubygems.org/ -a https://gems.ruby-china.com/
# 使用Gemfile和Bundle的項目,可以做下面修改,就不用修改Gemfile的source
$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com
# 刪除Bundle的一個鏡像源
$ bundle config --delete 'mirror.https://rubygems.org'
$ gem install jekyll bundler

3 測試搭建一個博客

Create a new Jekyll site at ./myblog.

$ jekyll new myblog
or 
$ jekyll new . --force

注意:如果卡住,這一步會存在一些依賴包的安裝。例如:x64-mingw32、 tzinfo-data、tzinfo (~> 1.2)、minima (~> 2.5)
查看依賴包

$  bundler list
Could not find gem 'minima (~> 2.5) x64-mingw32' in any of the gem sources
listed in your Gemfile.

安裝依賴包

$ gem install 64-mingw32、 tzinfo-data、tzinfo (~> 1.2)、minima (~> 2.5)

安裝64-mingw32遇到了困難:
Could not find gem ‘rails (= 4.2.4) x64-mingw32’
解決方法:

$ bundle install

Change into your new directory.

cd myblog

Build the site and make it available on a local server.

$ bundle exec jekyll serve
or (或者)
$ bundle exec jekyll s

Configuration file: C:/Users/XH/myblog/myblog/_config.yml
            Source: C:/Users/XH/myblog/myblog
       Destination: C:/Users/XH/myblog/myblog/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    done in 3.23 seconds.
 Auto-regeneration: enabled for 'C:/Users/XH/myblog/myblog'
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

當然也可以直接執行:

$ jekyll serve

Browse to http://localhost:4000

在這裏插入圖片描述

我們可以把myblog所有的文件拷貝到自己github博客項目下。以域名的方式訪問。

參考資料:
https://juejin.im/post/5b235a1cf265da597568a97d

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章