少女祈祷中...

最近折腾了一下hexo博客,在此将重要的地方记录下来

1、git操作

git连接远程仓库

1
2
3
4
5
6
7
8
# 初始化仓库
git init
# 连接远程仓库
git remote add <仓库名称> <仓库地址>
# 第一次提交,绑定分支
git add .
git commit -m "commit"
git push -u <仓库名称> <分支名称>

git连接子模块

1
git submodule add <仓库地址> <子模块目录>

git克隆

1
git clone <仓库地址> <仓库目录>

git命令设置别名

1
git config --global alias.up '!git add .;git commit -m "update";git push'

2、github actions操作

使用github actions实现子模块和父模块同步更新,代码如下
子模块:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
name: Trigger Parent Repository

on: [push]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Trigger Parent Repository
run: |
curl -L \
-v -X POST \
-H "Accept:application/vnd.github+json" \
-H "Authorization:token ${{secrets.TOKEN}}" \
-H "X-GitHub-Api-Version:2022-11-28" \
https://api.github.com/repos/<用户名>/<父模块仓库名>/dispatches \
-d '{"event_type":"${{ github.event.head_commit.message }}","client_payload":{"unit":false,"integration":true}}'

父模块:

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
name: Update Submodules

on: repository_dispatch

jobs:
update-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: master
ssh-key: ${{ secrets.SSH_KEY }}
- name: Set up Git
run: |
git config --global user.email "<用户邮箱>"
git config --global user.name "<用户名>"
- name: Update submodules
run: |
eval `ssh-agent -s`
ssh-add - <<< "${{ secrets.SSH_KEY }}"
git submodule init
git submodule update --recursive --remote
git add .
git commit -m "update"
git push
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock

创建.yml后缀的文件,放入.github/workflows目录下

3、部署博客

需要输入构建命令:

npm install -g hexo; hexo clean; hexo generate

该构建命令根据使用的主题不同会略有区别

输出目录设置为:public