現在的位置: 首頁 > 黃專家專欄 > 正文

Octopress 和 Git 的結合

2014年10月30日 黃專家專欄 ⁄ 共 1016字 ⁄ 字型大小 評論關閉

Octopress 是一個靜態博客系統,在我的 VPS 上搭建了這個 Blog 後,每一次寫新的日誌就需要在本機生成靜態頁面再通過 rsync 同步到伺服器,這是個繁瑣的過程,主要在於本機上也要安裝 ruby 環境和 Octopress。如果在其他受限的環境下就只能存儲編寫的 markdown 文件,存儲待以後發布或者 ssh 到 VPS 上發布,這是個比較噁心的過程。

Git 是一個分散式版本控制工具,如果 Blog 存儲在 git 伺服器上,那麼就將版本和存儲結合在一起,版本控制的天然優勢也可以被 Blog 系統所利用,任意回退到某一個時間的狀態就很容易實現。本文就將 Octopress 和 Git 結合在一起

VPS 搭建

1.安裝 RVM

按照 http://rvm.io 提示

1
$\curl -sSL https://get.rvm.io | bash -s stable

2.安裝 Ruby

Octopress默認使用的 Ruby 1.9.3

1
rvm install 1.9.3

3.安裝 OctoPress

1
2
3
4
git clone https://github.com/imathis/octopress.git
cd octopress
bundle install
rake install

4.安裝 nginx,將 web 目錄指定到你的 octopress 上

Git 伺服器搭建

1.將客戶端的公鑰加入伺服器端

2.建立一個目錄, 初始化 repository, 且改變遠程 repository 的工作目錄到網站需要部署的位置

1
2
3
4
5
git init --bare
git config core.bare false
git config core.worktree /path/web_directory
# /path/web_directory 是你的 web 目錄
git config receive.denycurrentbranch ignore

3.hooks 目錄中創建一個 post-receive 腳本(應該在.git/hook 裡面)

1
2
3
4
5
GIT_WORK_TREE=/path/web_directory git checkout -f
# 這行很重要,不然會有環境許可權問題
. /usr/local/rvm/scripts/rvm
cd /path/web_directory
rake generate 2>blog.log

4.成功

client 只要安裝個 git 就好了,同步 repository, 然後 commit, push, 就會發現文章自動發布了。 這篇文章就是這樣發布的:)

抱歉!評論已關閉.