将 Hexo 部署到 Github 上

主要参考

步骤

博客目录创建git仓库,推送至source分支

1
2
3
4
5
git init
git add .
git commit
git branch -M source
git push origin source

更改.github/workflows/pages.yml

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
29
30
31
32
33
name: Pages

on:
push:
branches:
- source # 监听push事件的分支,是博客源文件的分支

jobs:
pages:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.OS }}-npm-cache
restore-keys: |
${{ runner.OS }}-npm-cache
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
publish_branch: master # 部署的分支,是Github Pages对应的目录

注意一下分支名字即可。

更改项目Github Pages的源目录

在项目的Settings页的Pages标签里,将源目录改为master,保存就好了。

其他参考

这两个是Fluid主题给的教程,但是不太看得懂到底部署到哪儿去了,最后没有用。