创建放置hexo目录
1  | $ mkdir hexo  | 
安装hexo
1  | $ npm install -g hexo  | 
初始化hexo 会自动安装依赖
1  | $ hexo init  | 
启动服务
1  | $ hexo generate  | 
至此,本地博客搭建完成,可以本地通过(localhost:4000)进行访问
下面将本地博客部署到github
创建github账号
新建repository
仓库名以’github账号.github.io’命名
设置Custom domain
进入刚刚创建好的仓库中,从settings进入设置Custom domain并save(邮箱未验证的用户需要先进行邮箱验证)
本地绑定github账户
参考设置账号Setting up Git
设置SSH keys
参考设置sshGenerating a new SSH key
在hexo部署
编辑hexo/_config.yml1
2
3
4deploy:
  type: git
  repository: https://github.com/xxx/xxx.github.io.git
  branch: master
安装
1  | $ npm install hexo-deployer-git --save  | 
部署到github
1  | $ hexo generate  | 
到这里,就可以通过’github账号.github.io’访问博客了
个人使用主题
1  | git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia  | 
在hexo/_config.yml 进行主题更改
小技巧: 设置个人头像,可利用微博图床进行设置
hexo在本地引入图片失败解决方案
_config.yml 中配置
1
post_asset_folder:true
安装插件
1
npm install https://github.com/CodeFalling/hexo-asset-image --save
创建一篇新文章
会自动建立一个与文章同名的文件夹,您可以把与该文章相关的所有资源都放到那个文件夹,如此一来,您便可以更方便的使用资源
1  | hexo new test  | 
- 在文章中引用图片示例
1

 
同时托管coding.net和github
在_config.yml中配置
1  | deploy:  | 
总结
编辑文章在hexo/source/_posts/目录下
修改配置或者修改文章后都需要执行hexo generate命令方可生效
更新到github则需要执行hexo deploy命令重新部署
一段时间没更新博客,再使用的时候,发现$hexo command not found, 原因是node版本由之前的v5.12切换到了v6.6,临时解决办法nvm use 5.12.0