1.准备工作
安装nodejs
去官网下载nodejs安装(推荐安装0.12.x),安装之后在命令行 node -v,如果成功说明node环境ok,不成功就去环境变量配置一下.
安装hexo
使用命令 npm install hexo -g,执行hexo -v 查看版本,本教程适合3.1.1版本
安装git
去官网下载git安装,不会自行百度
配置git
配置ssh私钥,上传到github上
2.github-pages和gitcafe-page的说明
github有两种主页,一种是github-page(个人主页),一种是项目主页,本教程针对个人主页
gitcafe-page的个人主页只是在项目下有一个gitcafe-pages的分支,部署成功后访问主页即可
github-page需要将hexo博客发布到repository的master(主干)即可
gitcafe需要将hexo博客发布到repository的gitcafe-pages的分支
3.使用hexo写博客
- 新建一个文件夹myblog,- 右键git bash here使用git的shell- 在shell中输入hexo init,回车执行- 在shell中输入hexo g ,回车- 在shell中hexo s,回车- 去浏览器访问http://localhost:4000,访问到主页,然后在shell中ctrl c停止- 在shell中hexo new "first-blog",回车- 在shell中hexo g ,回车- 在shell中hexo s ,回车,在访问- ok,在本地测试就没问题了
4.发布到github和gitcafe
- 打开项目根部录下的.config.yml,找到deploy,修改如下:
deploy: - type: git repo: git@github.com:yourname/yourname.github.io.git,master - type: git repo: git@gitcafe.com:yourname/yourname.git,gitcafe-pages
- 如果只发布到github或者gitcafe上,修改如下:git的branch是master,gitcafe的是gitcafe-pages
deploy: type: git repo: <repository url> branch: [branch] message: [message]
5.常见问题
部署时出现git not found
npm install hexo-deployer-git --save 安装依赖包
博客效果可以看我的个人博客 我的个人博客