無為閣

為無為,事無事

Octopress 程式碼與網站內容的管理

草稿 - 尚未完成的文章,不會顯示在網誌上

Octopress 本身並不如 Wordpress一樣提供草稿功能,我與Octopress 搬家記 (2) – 程式碼與網站內容的管裡的作者一樣,還未完成的文章不想出現在我的Blog上。

程式碼及發表的文章,與 compiled HTML 隔離開來,且草稿先不公開。 草稿可以放到 dropbox ,而程式碼加上已發表的文章,可以放到 GitHub 公開出來

幸好這樣的需求可以利用git bracnh來達成,而與原文作者不同的是,我採用Octopress原先的設定,Deploy 到 Github 上。

  • master branch : 產生初來的Blog HTML,也就是 github pages branch
  • source branch : Octopress 源碼,文章。 一旦 Octopress 更新,只要把 Octopress 的 master merge 進來即可

為此我寫了一個小程式來減少重複的動作: Source (alpha version, 易爆),因為這個程式需要 python-ucltip 0.6 以上,而 Ubuntu 目前的版本是0.5-1,所以Ubuntu 的 user 請自己去pypi上 抓 source…所以我上傳了新版的python-ucltip同時也包了一個ocotopress-admin debian pacakge 給Ubuntu 11.10用,Ubuntu 11.10的使用者請使用下列指令(不過rvm你還是要自己裝啊!!)

1
2
3
4
add-apt-repository ppa:ossug-hychen/python-ucltip
add-apt-repository ppa:ossug-hychen/ppa
apt-get update
apt-get install octopress-admin

p.s 本來想包個 Debian Pacakge ,但Ubuntu 11.10 的 ruby-rvm 太舊了…

建立新的Blog:

1
2
3
$ octopress-admin new myblog
$ cd myblog
$ octopress-admin init
  1. 從 github 上抓下 Octopress 原始碼
  2. 並且安裝需要的bundle (必須事前設定好RVM環境)
  3. 執行rake setup_github_page

升級 Blog:

更新Octopress的源碼,本指令並不會影響到遠端的Blog網站,除非你執行octopress-admin deploy

1
$ octopress-admin upgrade
  1. 將最新的 Octopress 源碼合併的 source branch
  2. 安裝需要的bundle。

發佈到線上:

1
$ octopress-admin deploy
  1. checkout source branch
  2. source branch push 到github `source branch
  3. rake generate來重新 compile 整個站
  4. rake deploy 丟到 github master branch 上 (更新github上的Blog)

寫新文章:

每篇草稿都被放在單獨的drafts開頭的branch,所以只有sourcebranch上的文章會被編成html。

1
$ octopress-admin post 'hello'
  1. 開一個草稿 branch ,命名為 drafts/2011-12-04-hello
  2. checkout 到那個 branch ,然後開新文章、寫文章、 commit 他的 markdown 檔。

執行後的git log 長這樣

2011-12-04 Hsin-Yi Chen (hyc~ o [source] enable facebook like
2011-12-04 Hsin-Yi Chen (hyc~ │ o [drafts/2011-12-04-hello] start to write hiello
2011-12-04 Hsin-Yi Chen (hyc~ I─┘ Finished github deploy settings

查詢現在有多少草稿:

顯示目前放在 drafts開頭的branch 的 markdown 檔,同時顯示 draft 編號,供octopress-admin edit, octopress-admin publish 使用。

1
2
$ octopress-admin drafts
[1] source/_posts/2011-12-04-hello.markdown (branch: drafts/2011-12-04-hello)

繼續寫文章:

必須先用octopress-admin drafts 得知要編輯的草稿的編號,以下的 1 代表草稿1

1
$ octopress-admin edit 1
  1. checkout 到草稿的 branch
  2. 使用sensible-browser開啟你偏好的Editor修改這個 branch 的 markdown 檔案
  3. 你完成編輯後,請記得手動commit,這樣的設計是因為你可能只是暫時中斷編輯,而並不是完成一個段
1
$ git commit -m 'add new section: why'

執行後的 git log 長這樣

2011-12-04 Hsin-Yi Chen (hyc~ o [source] enable facebook like
2011-12-04 Hsin-Yi Chen (hyc~ │ o [drafts/2011-12-04-hiello] add new section: why
2011-12-04 Hsin-Yi Chen (hyc~ │ o [drafts/2011-12-04-hiello] start to write hiello
2011-12-04 Hsin-Yi Chen (hyc~ I─┘ Finished github deploy settings

定稿:

必須先用octopress-admin drafts 得知要公佈的草稿的編號,以下的 1 代表草稿1

1
$ octopress-admin publish 1
  1. 把該草稿的 branch 給 merge 進 srouce (使用 –no-ff 來產生 merge commit)。
  2. 刪除草稿的 branch (一旦定稿即不可回頭)

執行後的 git log 長這樣

2011-12-04 Hsin-Yi Chen (hyc~ M─┐ [source] Merge branch 'drafts/2011-12-04-hello' into source
2011-12-04 Hsin-Yi Chen (hyc~ │ o add new section: why
2011-12-04 Hsin-Yi Chen (hyc~ │ o start to write hello
2011-12-04 Hsin-Yi Chen (hyc~ o │ enable facebook like
2011-12-04 Hsin-Yi Chen (hyc~ o─┘ Finished github deploy settings

預覽 Blog:

原先的規劃是執行rake preview後,用sensible-browser直接開啟local的blog,目前只有rake preview的功能

1
blog preview

其他的指令

foreach:

對當前目錄下所有的Octopress Blog目錄執行指令, 下面這個指令是deploy所有的blog

1
$ octopress-admin foreach 'octopress-admin deploy'

結語:

Octopress 本身提供的管理系統非成有限,但也因此有更大的彈性作客製化。 目前這套script並沒有提供把草稿備份到Dropbox上的功能,需然要加也是可以….

現在這些已經滿足我的需求了,以後自己有需要再加吧!

如果你嫌octopress-admin指令太長,你可以跟我一樣把 alias 成blog

1
$ echo alias blog='octopress-admin' >> ~/.bashrc

Comments