octopress使用範例

Ubuntu 14.04 安裝Octopree


更新記錄

item note
20150615 第一版

目錄


安裝其它必要軟体

1
2
3
sudo apt-get install ruby1.9.1-dev
sudo apt-get install nodejs
sudo apt-get install rbenv

參考Octopress Setup

1
2
3
4
5
6
7
8
9
10
11
git clone git://github.com/imathis/octopress.git octopress
cd octopress

sudo gem install bundler
rbenv rehash # If you use rbenv, rehash to be able to run the bundle command
bundle install

- install octopress theme.

rake install

設定github blog

  • 先到github申請,設定庫名稱(username.github.io)
  • 輸入 git@github.com:username/username.github.io.git
1
rake setup_github_pages

其它相關說明

  • octopress 由git clone產生
  • octopress/source此為使用者個人的網頁修改記錄(記錄在source branch)
  • octopress/_depoly為使用者個人的github(記錄在master branch)
  • 若有git使用上問題,可以直接到octopress/_depoly目錄,直接執行git指令

先使用preview預覽網頁內容

  • 產生新的頁面
    1
    rake 'new_post["title"]'
  • rake generate ,參考source內容產生_deploy目錄內容
  • rake preview ,預覽產生內容

注意:記得將source 更新 & deploy

1
2
3
git add .
git commit -m "add new blog"
git push
  • rake deploy ,更新發布網頁內容(也可以直接到_depoly目錄內使用git指令)

已存在github網頁,如何checkout到octopress

  • 下載已存在github blog及切換到source branch
1
2
3
git clone git@github.com:erwinchang/erwinchang.github.io.git blog
cd blog
git checkout --track origin/source
  • 目前git目錄訊息如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(source-bdcf6ca)1h41m erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io$ cat .git/config                                                                                                                                  
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:erwinchang/erwinchang.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[branch "source"]
remote = origin
merge = refs/heads/source
(source-bdcf6ca)1h41m erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io$ git status
On branch source
Your branch is up-to-date with 'origin/source'.
  • 安裝rake相關工具 及執行gen_deploy(此時會有錯誤)
1
2
3
gem install bundler
bundle install
rake gen_deploy
  • 產生deploy目錄及更新到最新
1
2
3
4
5
mkdir _deploy
cd _deploy
git init
git remote add origin git@github.com:erwinchang/erwinchang.github.io.git
git pull origin master
  • 操作訊息如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 (master-) erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io/_deploy$ git init
Reinitialized existing Git repository in /opt/data2/data/github/erwinchang.github.io/_deploy/.git/
(master-) erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io/_deploy$ ls
(master-) erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io/_deploy$ git remote add origin git@github.com:erwinchang/erwinchang.github.io.git
fatal: remote origin already exists.
(master-) erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io/_deploy$ ls
(master-) erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io/_deploy$ git pull origin master
Enter passphrase for key '/home/erwin/.ssh/id_rsa_github':
remote: Counting objects: 283, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 283 (delta 0), reused 0 (delta 0), pack-reused 281
Receiving objects: 100% (283/283), 248.99 KiB | 299.00 KiB/s, done.
Resolving deltas: 100% (92/92), done.
From github.com:erwinchang/erwinchang.github.io
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
  • 更新branch source到最新的及產生新的網頁內容(public)且更新到git server(由_depoly目錄產生)
1
2
3
4
git pull origin source
rake generate
rake preview
rake deploy
  • 操作訊息如下
1
2
3
4
5
6
7
8
9
10
(source-bdcf6ca)2h16m erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io$ git pull origin source
Enter passphrase for key '/home/erwin/.ssh/id_rsa_github':
From github.com:erwinchang/erwinchang.github.io
* branch source -> FETCH_HEAD
Already up-to-date.
(source-bdcf6ca)2h16m erwin@erwin-minipc:/opt/data2/data/github/erwinchang.github.io$ git status
On branch source
Your branch is up-to-date with 'origin/source'.

nothing to commit, working directory clean
  • 之後就可以正常rake geanerate/rake preive/rake deploy

參考來源