Hank Lin

A new blog

Octopress Blogging

| Comments

Octopress - A blogging framework for hackers

Octopress是一套基於Jekyll的blogging framework,概念是產生靜態的網頁,然後用Github幫你服務網頁。
如他的副標題所說的,是一套「給hackers用的blogging framework」。雖然沒真的那麼誇張,但是仍然要熟悉命令列、github、ruby、markdown、 html等等。但是熟悉了之後,效率會很高。
現在我也試著從原本的wordpress改成Octopress,以前的舊文章也會慢慢轉過來。
以下是我的筆記,由於因緣際會我現在只有Windows電腦,所以下面都是Windows的作法,Mac或Linux之後再試試。

準備環境

要有git命令列,Windows上可以用Git scm,或是GitHub for Windows
要有Ruby,Windows就用Ruby Installer

1
2
$ ruby --version
ruby 1.9.3p374 (2013-01-15) [i386-mingw32]

Ruby版本要1.9.3以上。

安裝Octopress

在這裡是安裝到octopress目錄下。

1
2
3
4
5
$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress
$ gem install bundler
$ bundle install
$ rake install

bundle install可能遇到
Gem::InstallError: The 'fast-stemmer' native gem requires installed build tools.
的錯誤,解決方法就是安裝DevKit,一樣從Ruby Installer網站下載,我是安裝在devkit這個目錄下。

1
2
3
$ cd devkit
$ ruby dk.rb init
$ ruby dk.rb install

在Windows有惱人的CP950字碼問題,我在Gemfile加了

1
2
3
4
5
6
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
if RUBY_VERSION =~ /1.9/
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
end

並且加了環境變數

1
2
set LANG="en_US.UTF-8"
set LC_ALL="en_US.UTF-8"

Hello Octopress World

設定的東西在octopress/_config.yml,但是現在先不管他,我先寫一篇丟上來。

1
$ rake new_post["hello world"]

這樣會產生一個octopress/source/_posts/yyyy-MM-dd-hello-world.markdown檔案,在裡面寫些markdown吧。
寫好了之後,可以用以下的指令先看看成果

1
$ rake generate

會產生最後的網頁檔案,而

1
$ rake watch

會持續觀察sourcesass目錄下檔案的變化,並主動regenerate成果。

1
$ rake preview

會開一個伺服器,讓你可以在http://localhost:4000/
瀏覽自己的作品。

丟上GitHub

GitHub有兩種選擇可以服務網頁:User/Organization pages或Project pages (gh-pages)。差異不大,兩者都可以使用自訂網域名稱。在這裡我使用Project pages。

1
2
3
$ rake setup_github_pages
$ rake generate
$ rake deploy

執行rake setup_github_pages用來告訴octopress我們要使用的GitHub的Repository資訊,格式是:git@github.com:your_username/your_projectname
rake deploy這個指令就真的會把網頁傳上GitHub了。在這一步我在Windows上又有問題,我用GitHub for Windows的Git Shell去執行這個指令才能傳上GitHub。
如果是產生第一次的網頁,GitHub可能會10分鐘才初始化好環境。但是初始化好之後,隨時佈署上GitHub,看到的就都是最新的內容。

Comments