經過在網上各種找資料,踩過各種坑,終於搭建好了hexo,直接與gitbub一起使用,搭建起自己的免費的博客。
關於Hexo
Hexo是一款基於Node.js的靜態博客框架。
Hexo特性
- 風一般的速度
Hexo基於Node.js,支持多進程,幾百篇文章也可以秒生成。 - 流暢的撰寫
支持GitHub Flavored Markdown和所有Octopress的插件。 - 擴展性
Hexo支持EJS、Swig和Stylus。通過插件支持Haml、Jade和Less.
博客搭建思路
搭建過程
① 安裝Node.js
② 安裝Git
③ Github倉庫准備
1. 創建倉庫,http://your-user-name.github.io
2. 創建兩個分支:master 與 hexo
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/your-user-name/your-user-name.github.io.git
git push -u origin master
在本地新建一個分支:
git branch hexo
切換到你的新分支:
git checkout hexo
將新分支發布在github上:
git push origin hexo
至此分支創建完畢
3. 在github網站設置hexo為默認分支
④ Hexo創建
在本地your-user-name.github.io文件夾下通過Git bash依次執行
1. npm install hexo
2. hexo init <folder>
如果指定 <folder>,便會在目前的資料夾建立一個名為 <folder> 的新資料夾;否則會在目前資料夾初始化。
3. npm install
4. npm install hexo-deployer-git
5. hexo generate 生成網站
6. hexo server 啟動本地服務器
網站會執行在http://localhost:port (port 預設為 4000,可在 _config.yml 設定)
⑤ Hexo和Github關聯
1. 修改_config.yml中的deploy參數,分支應為master;
2. hexo generate -deploy(可以簡化為hexo g -d) 生成推送到github的master分支
此時訪問your-user-name.github.io即可查看生成的站點內容
⑥ Hexo源碼備份
1. 進入本地的your-user-name.github.io文件夾下
2. git clone https://github.com/your-user-name/your-user-name.github.io.git
此時顯示分支為hexo
3. git add --all
4. git commit -m "blog source commit"
5. git push origin hexo
至此博客源代碼就備份到了hexo分支上面。
⑦ 后期維護以及博客更新
在本地對博客進行修改(添加新博文、修改樣式等等)后,通過下面的流程進行管理。
- 依次執行git add .、git commit -m "..."、git push origin hexo指令將改動推送到GitHub(此時當前分支應為hexo);
- 然后再執行hexo g -d發布網站到master分支上。