使用私有仓库存放博客源码, 将Hugo构建好的public
目录推送到公有仓库来发布, 参考peaceiris/actions-gh-pages
的README。
- 创建一个私有仓库用来存放博客源码。
- 创建一个公有仓库用来发布博客。
- 创建一个个人token, 名字为了方便记住它的用途, 可以叫做blog。
- 到期日期选择No expiration。
- 作用域选择repo和workflow。
- 生成token, 复制它的值。
- 到博客源码仓库的Settings→Secrets中新建一个Actions secrets, 名为blog, Value粘贴上一步的个人token的值。
- 在博客源码仓库的根目录下创建
.github/workflows/gh-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
34
| name: GitHub Pages
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.0.0
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.4.13
with:
hugo-version: 'latest'
extended: true
- name: Build
run: hugo --gc --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3.7.3
with:
github_token: ${{ secrets.blog }}
external_repository: #用来发布博客的公有仓库名称
publish_branch: master
publish_dir: ./public
cname: #填写自定义域名
|
- 创建一个公有仓库用来存放博客源码。
- 在博客源码仓库的根目录下创建
.github/workflows/gh-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
| name: GitHub Pages
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.0.0
with:
submodules: false
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2.4.13
with:
hugo-version: 'latest'
extended: true
- name: Build
run: hugo --gc --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3.7.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }} #GITHUB_TOKEN不需要手动设置, GitHub会分配临时token
publish_dir: ./public
cname: #填写自定义域名
|
- CircleCI、Cloudflare Pages、Netlify、Travis CI、Vercel等。
警告
Cloudflare Pages的.pages.dev
域名似乎已被墙, 如果使用Cloudflare Pages, 建议自定义域名, 然后DNS设置为Cloudflare代理。
- 使用Nginx在自己服务器上部署, 参考Nginx部署Hugo站点。