0%

使用GitHub Actions完成Hexo源码与编译后分离部署

部署过程就不多说了,网上很多现成的教程。就直接放actions代码了。

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
35
36
37
38
39
40
name: Deploy Blog to DeployRes
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Dependencies
run: npm install
- name: Generate Static Files
- name: Update 'updated' field in posts
run: |
for file in source/_posts/*.md; do
last_commit_date=$(git log -1 --format="%ci" -- $file)
if grep -q '^updated: ' $file; then
sed -i "s/^updated: .*/updated: $last_commit_date/" $file
else
sed -i "/^title: .*/a\updated: $last_commit_date" $file
fi
done
run: npx hexo generate
- name: Deploy to DeployRes
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.BLOG_DEPLOY_TOKEN }}
publish_dir: ./public
publish_branch: master
destination_dir: blog
external_repository: [用户名]/[编译文件存放的项目名]

主题下载的时候使用了git拉取,导致提交的时候还发生了项目冲突,使用的主题文件夹变成了一个文件。
后面删除主题以子项目的方式拉取才正常。
如果不是用子项目的话可以删除这部分:

1
2
3
with:
submodules: true
fetch-depth: 0