前言
其實使用了Octopress一陣子,就感覺在產生靜態檔案有點慢,也不曉得是不是在 windows 上的關係,加上之前就有在考慮是否使用Hexo了,就決定轉換使用[Heox]+Github。
安裝
要安裝Hexo,首先必須要安裝Node.js與Git,不太清楚的部分可以觀看官方的文件,這兩者都安裝完畢再執行以下命令
hexolink1 2 3 4 5 6 7 8 9
| npm install hexo-cli -g
hexo init blog
cd blog npm install
hexo server
|
這樣就算安裝完成了。
資料轉移
我原本是使用Octopress,現在要轉到Hexo上,需要將 Octopress 安裝資料夾的source/_posts這內中的檔案,全部複製一份到Hexo的安裝資料夾下source/_posts的位置,其他方式的移轉可以參考官方文件。
佈署
Hexo 的佈署需要另外安裝 npm 的套件
| 佈署類型 |
套件安裝名稱 |
| Git |
hexo-deployer-git |
| Heroku |
hexo-deployer-heroku |
| Rsync |
hexo-deployer-rsync |
| OpenShift |
hexo-deployer-openshift |
| FTPSync |
hexo-deployer-ftpsync |
我是使用 git,所以使用以下指令進行安裝
1
| npm install 套件安裝名稱 --save
|
附上我的package.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| { "name": "hexo-site", "version": "0.0.0", "private": true, "hexo": { "version": "3.1.1" }, "dependencies": { "hexo": "^3.1.0", "hexo-deployer-git": "0.0.4", "hexo-generator-archive": "^0.1.2", "hexo-generator-category": "^0.1.2", "hexo-generator-feed": "1.0.3", "hexo-generator-index": "^0.1.2", "hexo-generator-sitemap": "1.0.1", "hexo-generator-tag": "^0.1.1", "hexo-renderer-ejs": "^0.1.0", "hexo-renderer-marked": "^0.2.4", "hexo-renderer-stylus": "^0.3.0", "hexo-server": "^0.1.2" } }
|
接著在 Hexo 目錄的_config.yml進行設定(不是 themes 裡面的_config.yml),找到 deploy 這行,進行如下設定,repo 更改為自己的位址,message 可以自己自定一下。
佈署link1 2 3 4 5
| deploy: type: git repo: git@github.com:shunnien/shunnien.github.io.git branch: message: Site updated at {{ now("YYYY-MM-DD HH:mm:ss") }}
|
這樣設定就都完成了,直接使用指令佈署到 Github 上
最後把原始碼加入到版控上,先在 Hexo 資料夾下建立新分支(hexo 安裝的資料夾下)
1 2 3 4 5 6 7 8 9 10 11 12
| git init
git remote add origin 你的Github位址
git checkout --orphan 新分支名稱
git add .
git commit -m "chang to hexo"
git push orgin 新分支名稱
|
參考資料