依赖

1
2
GitHub Pages
hexo-deployer-git

GitHub Pages

创建仓库

https://github.com/new

Repository namebGp8TUSc4Se8nlH5,选Public,勾选Add a README file,点击Create repository

new

打开Pages服务

打开仓库的setting,找到GitHub Pages,none下拉选main,点击保存,出现GitHub Pages source saved.成功,往下拉回到GitHub Pages,双击能打开网址https://weilining.github.io/bGp8TUSc4Se8nlH5/ ,显示bGp8TUSc4Se8nlH5即可正确开启。
setting

Pages

success

Pages link

web success

Hexo推送到GitHub Pages

生成令牌

在浏览器新建一个标签页,前往 GitHub 新建 Personal Access Token,只勾选 repo 的权限并生成一个新的 Token。Token 生成后请复制并保存好。

new

token

token

copy token

安装插件

blogroot下运行

1
2
npm i hexo-deployer-git
npm ls --depth 0

install hexo-deployer-git

配置hexo

_config.ymldeployroot 按照下面修改

1
2
3
4
5
6
7
8
9
10
root: /bGp8TUSc4Se8nlH5/
deploy:
- type: git
repo:
github:
url: https://github.com/weilining/bGp8TUSc4Se8nlH5.git # GitHub Pages 的https
branch: main # GitHub Pages的分支
token: 6792f6a8d70e916ca6fb944adbcda2d47d54dfb4 #GitHub_Personal_Access_Token # 获取教程 https://weilining.cf/3.html
name: name # GitHub用户名
email: email@gmail.com # GitHub登陆邮箱

推送

1
hexo cl && hexo d

获取 GitHub Personal Access Token 方法

1
2
3
4
graph TD
A(GitHub Pages)-->B1(用户weilining.github.io)
A-->B2(组织weilining.github.io)
A-->B3(项目weilining.github.io/hello)

两种部署方式

1
2
3
graph TD
A(部署GitHub Pages)-->B1(GitHub Action 自动)
A-->B2(hexo-deployer-git 手动)

部署可以用 GitHub Action 自动构建,也可以使用本地 hexo cl && hexo d 手动推送。

参考

Creating a GitHub Pages site

GitHub Pages

hexo-deployer-git