【Hexo】使用Hexo搭建github博客

1.创建github帐号,新建一个以用户名.github.io命名的仓库

2.安装git,创建ssh

1
2
3
4
5
ssh-keygen -t rsa -f ~/.ssh/id_rsa_github
#用于创建ssh,会有公钥和私钥,将公钥中的内容拷贝到github帐号 Settings > SSH and GPG keys 中
ssh -T git@github.com
#用于测试是否成功

输入yes,其他使用默认即可,配置git

1
2
git config --global user.name "cnfeat"//用户名
git config --global user.email "cnfeat@gmail.com"//邮箱

3.下载并安装hexo

4.新建一个目录用于放置本地博客

1
2
3
4
5
6
7
8
mkdir hexo
cd hexo
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo g
hexo s #可以在本地http://localhost:4000/查看

5.修改blog目录下的_config.yml文件中的deploy:

1
2
3
4
deploy:
type: git
repository: git@github.com:xxxxxx/xxxxxxx.github.io.git
branch: master

6.安装hexo中关于git的组件,上传部署(需要cd到hexo\node_modules\hexo\Hexo目录)

1
2
3
4
5
npm install hexo-deployer-git --save
hexo clean
hexo g
hexo d

如果出现问题请参考使用hexo d无法上传问题解决办法然后再使用以上代码

参考: