緣起
日前幫朋友安裝設定
Hexo環境時發覺,
Node.js對一般使用者來說實在太遙遠, 為了執行 Hexo,需另安裝 Xcode(Mac) 與許多相關的開發環境,那不是一般使用者會用上的東西。 在那之後就不斷注意能簡化 Hexo 入門門檻的設定流程。
看到
珠聯璧合:利用 Koding 為靜态部落格搭建線上編輯環境,覺得是個不錯的解決方案。
利用 Koding 雲端開發環境,使用者無須在本機端安裝 Node.js 執行環境。 雖仍需花時間設定 Koding 上的環境,但可跨電腦、平台編寫與釋出部落格, 外出旅行時,一台平闆電腦就可以編寫與釋出部落格文章了!
Koding 簡介
我知道你和
PCMan一樣隻想看範例,以下簡介可以略過

Koding 是個雲端開發與社群平台,提供 Linux 虛拟主機環境與完整的 WebUI, 可以透過浏覽器在 Koding 上進行主機配置、架設網站與系統開發測試等。
- koding 提供完整 Linux 作業系統 (Ubuntu 13.04, Raring Ringtail)
- 提供 sudo 以安裝系統軟體與操作
- 預設安裝好 npm
- 預設安裝好 git
- 預設架好 apache
koding.com這是一個免費的雲端開發平台,也相當于透過浏覽器去操作一個VM > (virtual > machine),可以完全依照自己的需要去部屬開發環境、架設網站等等,這主機也可以執行JavaScript、PHP、Perl、Python、Ruby等語言,寫完可以線上上預覽、執行。不過要注意的是有基本容量限制1G。
他也有社交的功能,就像一般社交網站一般,可以發文分享、讨論交流,也有為數不少不同類型的Group,他把社交化功能與Web > IDE結合得還不錯。遇到一些開發相關問題,也還可以透過線上的社群直接發問。
[筆記] 13/12/02 Node.js分享講座 之 Koding « > 菜鳥的更新日記
goo.gl/zPL7nV/
本篇介紹如何設定 Koding 上的環境。
預備工作
申請方式和一般網站大同小異,~~我很懶~~這兒就跳過不介紹如何申請了。帳号申請後請記得收信驗證信箱位址。
安裝 Hexo 執行環境
注冊後連上 Koding 網站,點選左上方功能列的 "Terminal",可看到畫面如下:
因 Koding 預設已安裝好 Node.js / npm 環境,直接輸入下列指令即可安裝 Hexo 系統。
sudo npm install -g hexo
輸入後會看到 npm 開始安裝 hexo 如下:
npm http GET https://registry.npmjs.org/hexo
npm http 304 https://registry.npmjs.org/hexo
npm http GET https://registry.npmjs.org/async/0.2.9
npm http GET https://registry.npmjs.org/express/3.4.7
...
[email protected] /usr/lib/node_modules/hexo
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
跑完後可以執行
hexo
确認是否已正确安裝
$ hexo
若 hexo 安裝正确,會出現簡單說明訊息如下:
Usage: hexo <command>
Commands:
help Get help on a command
init Create a new Hexo folder
migrate Migrate your site from other system to Hexo
version Display version information
Global Options:
--config Specify config file instead of using _config.yml
--debug Display all verbose messages in the terminal
--safe Disable all plugins and scripts
--silent Hide output on console
For more help, you can use `hexo help [command]` for the detailed information
or you can check the docs: http://zespia.tw/hexo/docs/
設定 Hexo 部落格專案資料夾
安裝完
hexo
後需要建立 hexo 部落格專案資料夾,裡面存放部落格文章、布景主題、Plugins...等。
Init hexo blog folder
透過下列指令可在 Koding VM 的
{$HOME}/blog
建立 hexo 專案資料夾
$ cd
$ mkdir blog
$ cd blog
$ hexo init
輸入後可看到 Hexo 初始化專案資料夾如下:
[info] Creating file: source/_posts/hello-world.md
[info] Creating file: package.json
[info] Creating file: .gitignore
[info] Copying file: _config.yml
[info] Copying file: scaffolds/draft.md
[info] Copying file: scaffolds/page.md
[info] Copying file: scaffolds/photo.md
[info] Copying file: scaffolds/post.md
[info] Creating folder: source/_drafts
[info] Creating folder: scripts
[info] Copying theme data...
[info] Initialization has been done. Start blogging with Hexo!
更換部落格布景主題
Themes這兒有 Hexo 部落格布景主題清單,可找個喜歡的部落格布景。 大多數的部落格布景安裝方式都雷同。以下以
AWE為範例說明:
$ cd ~/blog
$ git clone https://github.com/kywk/hexo-theme-awe.git themes/awe
利用
Koding
的編輯器修改
_config.yml
,将
theme
設成
awe
_config.yml
為部落格主要設定資訊,部落格标題、作者資訊亦在這個檔案進行設定。
在 Koding 的編輯器看到資料夾結構如下圖:
配置 Github
Hexo 生成的部落格為靜态檔案,可直接 hosting 在任何 Web Server 上,相當多人将其放置于 Github 上。 Github Page 分成 Personal/Project 兩種,本文僅介紹 Personal Page 的設定。
Github Page 設定
先在 Github 上建立一個新的 repository,專案名稱需為
你的帳号.github.io
然後修改
_config.yml
中 deploy 資訊如下,可直接利用
Koding ACE
編輯器進行修改
deploy:
type: github
repository: https://github.com/你的帳号/你的帳号.github.com.git
branch: master
ssh-key
為友善存取 Github,建議建立 ssh-key。以下僅簡述步驟,詳細介紹在
Generating SSH Keys · GitHub Help在終端機輸入指令:
$ ssh-keygen -t rsa -C "[email protected]"
利用編輯器開啟
~/.ssh/id_rsa.pub
,參考
Generating SSH KeysStep3 的步驟, 将
~/.ssh/id_rsa.pub
的内容貼上 Github.
Happy blogging
上述步驟完成後,即可利用浏覽器在 Koding 上正常操作 Hexo 來建立部落格文章與釋出到 github 了。
建立新文章
$ hexo new "title"
釋出到 github
$ hexo d (deploy)
在 Koding 上建立 hexo 環境最大的好處是跨平台、裝置,可以随時随地編寫部落格文章, 無須安裝 Node.js / Git / ... 等開發工具。 然而文章都放在 Koding 上亦有網路速度不佳與存取不便的缺點。