title: 記錄第一次搭建hexo
date: 2016-11-22 14:57:37
type: "hexo"
tags:
- 搭建hexo
即使扒了很多大佬的搭建教程,還是踩了很多坑,所以打算記錄下來自己的搭建過程。本文主要介紹win10下hexo3.1.1搭建,并發(fā)布到GitHub上。
環(huán)境搭建
安裝nodejs(必須)
- 作用:用來生成靜態(tài)頁面的
- 方法:到node.js官網(wǎng)下載并安裝。我是用的是win10下v6.9.1版本。
安裝git(必須)
- 作用:把本地的hexo內(nèi)容提交到github上去。
- 方法:進入git官方下載即可,速度較慢。
申請GitHub賬號(必須)
安裝并搭建hexo
安裝hexo
- 進入git或cmd執(zhí)行以下命令
npm install -g hexo
- hexo必備插件,建議一起安裝
$ npm install hexo-generator-index --save #索引生成器
$ npm install hexo-generator-archive --save #歸檔生成器
$ npm install hexo-generator-category --save #分類生成器
$ npm install hexo-generator-tag --save #標簽生成器
$ npm install hexo-server --save #本地服務(wù)
$ npm install hexo-deployer-git --save #hexo通過git發(fā)布(必裝)
$ npm install hexo-renderer-marked@0.2.7--save #渲染器
$ npm install hexo-renderer-stylus@0.3.0 --save #渲染器
- 安裝過程中不知道為毛我多了兩個蜜汁報錯,但到最后也沒太大影響
npm WARN deprecated swig@1.4.2: This package is no longer maintained
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevent@^1.0.0(node_modules\hexo\node_modules|chokidar\node_mdules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
- 初始化
選擇本地磁盤某個位置創(chuàng)建本地hexo文件夾,進入后右鍵 git bash
`1 $ hexo init`
- 生成靜態(tài)頁面
`2 $ hexo p`
- 本地服務(wù)
必須安裝 hexo server,否則無用
`3 hexo s`
至此本地hexo已建立成功,測試網(wǎng)址:[http://localhost:4000](http://localhost:4000/)
## 配置GitHub
- 建立Repository
建立與你用戶名對應(yīng)的倉庫,倉庫名必須為【your_user_name.github.io】
現(xiàn)在我們需要編輯_config.yml文件:
翻到最下面,改成我這樣子的
deploy:
type: git #有的版本是github也是個小坑,注意
repo: https://github.com/xunfeng911/xunfeng911.github.com.git
#我的github是xufeng911 換成你本人的
branch: master
然后保存后執(zhí)行命令:
hexo d
注意yml格式文件冒號后面必須加一個空格
執(zhí)行完畢后訪問your_user_name.github.io
即可看到部署在github上的默認博客,第一次發(fā)布可能會有10分鐘的延遲。
###### 到這里,一個全新的hexo博客就建成了。
## 附錄
### 常用命令:
hexo new "postName" #新建文章
hexo new page "pageName" #新建頁面
hexo generate #生成靜態(tài)頁面至public目錄
hexo server #開啟預(yù)覽訪問端口(默認端口4000,'ctrl + c'關(guān)閉server)
hexo deploy #將.deploy目錄部署到GitHub
hexo help # 查看幫助
hexo version #查看Hexo的版本
### 簡寫
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
## 參考資料
[盧睿韜學(xué)長的自留地](https://xdlrt.github.io/2016/02/16/2016-02-16/)
[潘柏信,搭建個人博客](http://baixin.io/2015/08/HEXO搭建個人博客/)