github搭建Hexo博客过程

准备工作

  1. 安装git。
  2. 安装Node.js。
  3. 安装Hexo。
1
2
#git bash
$ npm install hexo -g

检查:

1
2
3
$ hexo -v
$ git --version
$ node -v
  1. 安装hexo依赖
1
2
#git bash
$ npm install --save hexo-deployer-git

配置ssh-key

1
2
3
4
5
6
7
8
9
10
#git bash
User@LAPTOP-TQ97MGKO MINGW64 ~/Desktop
$ cd ~/.ssh/

User@LAPTOP-TQ97MGKO MINGW64 ~/.ssh
$ pwd
/c/Users/User/.ssh

User@LAPTOP-TQ97MGKO MINGW64 ~/.ssh
$
  1. 配置ssh。
1
2
#git bash
$ ssh-keygen -t rsa -C "Github邮件地址" -> 连续三次回车
  1. 将.ssh文件夹下的id_rsa.pub内的内容全部复制到github主页个人设置里面的Settings->SSH and GPG keys->New SSH key中。
  2. 测试是否成功
1
2
#git bash
$ ssh -T git@github.com
  1. git config设置自己的用户名、邮箱。
1
2
3
#git bash
$ git config --global user.name "aaaa" #你的github用户名
$ git config --global user.email "bbbb" #填写你的github注册邮箱
  1. 初始化
1
2
#git bash
$ hexo init
  1. 自选主题(Butterfly),在Hexo根目录中
1
2
3
4
#git bash
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
npm install hexo-renderer-pug hexo-renderer-stylus --save
npm install hexo-deployer-git --save

并将_config.yml中的theme改成butterfly.

上传

创建repository,名字选wbohan.github.io,Add a README file.

然后在config.yml中修改deploy:

1
2
3
4
5
#config.yml
deploy:
type: 'git'
repository: git@github.com:aaaa/aaaa.github.io.git
branch: main

Hexo g -d即可上传Blog.