GitHub Pages + Hexo 简明教程
一次简单记录
GitHub Pages + Hexo
安装 nodejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20$ npm -v
9.5.1
$ npm config set registry https://registry.npmmirror.com
# 安装 hexo
$ npm i hexo-cli -g
changed 60 packages in 31s
npm notice
npm notice New minor version of npm available! 9.5.1 -> 9.6.4
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.6.4>
npm notice Run `npm install -g npm@9.6.4` to update!
npm notice
$ hexo -v
# 初始化目录
$ hexo init
# 生成页面
$ hexo g
# 启动本地服务
$ hexo s安装 git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28# 基础操作(工作区 → 暂存区 → 本地仓库区 → 远程仓库区)
git status
git add
git commit
git log
git remote add origin git@github.com:xxx
git push -u origin master
# 配置用户信息
git config --global user.name "hcjjj"
git config --global user.email "hcjjj@foxmail.com"
git config --global --list
# 生成密钥SSH key
ssh-keygen -t rsa -C "hcjjj@foxmail.com"
# 填入 github 设置的 SSH and GPG keys
$ cat C:\Users\hcjjj/.ssh/id_rsa.pub
# 验证
$ ssh -T git@github.com
Hi hcjjj! You've successfully authenticated, but GitHub does not provide shell access.
# 若:ssh: connect to host github.com port 22: Connection timed out
$ ssh -T -p 443 git@ssh.github.com
Hi hcjjj! You've successfully authenticated, but GitHub does not provide shell access.
$ vim ~/.ssh/config
```
# Add section below to it
Host github.com
Hostname ssh.github.com
Port 443
```推送到 github
在博客根目录下,安装扩展:
npm i hexo-deployer-git
修改目录下的
_config.yml
文件:1
2
3
4
5
6
7
8# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
# repository: https://github.com/hcjjj/hcjjj.github.io.git
# 如果经常推送失败用下面这个方式
repository: git@github.com:hcjjj/hcjjj.github.io.git
branch: master1
2
3
4
5
6# 生成静态网页
hexo g
# 本地预览
hexo s
# 上传到github
hexo d