介绍

在hexo themes 里看到有简历的模版,于是想把它和主站博客整合到一起的想法。

有一个私人项目:blog ,一个公共项目 username.github.io, 现在使用 hexo 写源码放到 blog 中,通过github action 创建静态网站,并设置到 公共项目 username.github.io 分支 gh-pages 作为 pages. 现在我想 再创建一个 resume的私人项目,也是一个 Hexo 网站,写到 username.github.io 分支 gh-pages 的 /resume 下。

思路一句话:
“resume 仓库自己 hexo g → 把产物 public/* 推到 blog 仓库的 resume-dist 分支(空分支即可) → blog 主 Action 在生成完主站后,再把 resume-dist 分支里的文件整个 拷到 public/resume/ → 最后统一 pushusername.github.iogh-pages。”

这样做的好处:

  • resume 源码完全私有;
  • 主站 Action 只拉产物,不拉源码;
  • username.github.io 来说只是多了一个 /resume 目录,毫无感知。

一、给 resume 仓库配极简 Action

文件:.github/workflows/build.yml(放在 resume 仓库)

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: Build Resume Hexo

on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- run: npm ci
- run: npx hexo generate

# 把产物推到 blog 仓库的 resume-dist 分支
- name: Deploy to blog/resume-dist
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.PAT }} # 需有 repo 权限
external_repository: yourname/blog # 你的私人 blog 仓库
publish_branch: resume-dist # 空分支即可,会自动创建
publish_dir: ./public
commit_message: "chore: update resume dist"

二、改造 blog 主 Action(关键 4 行)

在你 blog 仓库.github/workflows/*.yml 里,找到 hexo g 之后、deploy 之前 的位置,插入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. 拉取 resume 产物
- name: Fetch resume dist
uses: actions/checkout@v4
with:
repository: yourname/blog # 自己仓库
ref: resume-dist
token: ${{ secrets.GITHUB_TOKEN }}
path: resume-dist

# 2. 合并到主站 public/resume/
- name: Merge resume into public
run: |
mkdir -p public/resume
cp -r resume-dist/* public/resume/

然后继续你原来的 Deploy to username/username.github.io 步骤即可(peaceiris/actions-gh-pages 或 JamesIves/github-pages-deploy-action 都行)。

最终目录结构:

1
2
3
4
5
public/
index.html … # 博客
archives/ …
resume/ # 简历站点
index.html …

三、需要准备的 2 个 Secret

  1. resume 仓库 → Settings → Secrets → Actions
    新建 PAT:Personal Access Token,勾选 repo 权限,用于把产物推到 blog 仓库。

  2. blog 仓库
    如果原来已经配过推到 username.github.io 的 Token,无需再改;
    拉取 resume-dist 分支用默认 GITHUB_TOKEN 即可(同一仓库)。


四、验证流程

  1. 给 resume 推代码 →
    Action 绿 →
    打开 https://username.github.io/resume/ 就能看到最新简历。
  2. 给 blog 推代码 →
    主站 Action 绿 →
    博客 & 简历同时在线,互不影响。

可选优化

  • 给 resume 单独配主题、插件、甚至 Node 20 都行,主站完全无感。
  • 如果想再增加「portfolio」站点,同理再建一个 portfolio-dist 分支即可。

按照官网教程先把 hexo 在本地安装好

官网教程

1
$ npm install -g hexo-cli

然后再执行: hexo init your-blog-directory,相当于这个 hexo-cli 初始化了一个博客目录。

博客美化: 使用 next 主题

参考这篇文档:Hexo + NexT主题美化GitHub博客

Github Page 自动化发布

在自己的 Github 下创建2个 Repo, 一个以 username/username.github.io 另一个可以是 private 的repo,比如 blog,用于存 hexo 的源码。
流程就是,在 blog 项目里写博文,然后通过 Github Action 推动到 username.github.io 的分支 gh-pages 用于发布。blog 项目可以是私有的,这样就可以隔离源码和发布后的 public 文件夹。

一、仓库准备

源码仓库(任选其一)
新建 blog-src(私有更好,防止草稿泄露)。
把本地 Hexo 根目录全部文件(含 package.json、_config.yml、主题目录、source/、scaffolds/ 等)推送到该仓库。
GitHub Pages 仓库
若尚未创建,新建 username.github.io(公开)。
进入该仓库 → Settings → Pages → Source 选 “GitHub Actions”,不要选 branch,否则后面 Actions 会冲突。

二、一次性密钥配置

Actions 需要有权把构建结果推送到 username.github.io 仓库,最简办法:
生成仅用于部署的 Personal Access Token
GitHub 头像 → Settings → Developer settings → Personal access tokens → Tokens (classic) → Generate new token (classic)
勾选 repo 全部权限,过期时间选 “No expiration” 或 90 天,复制生成的 token。
把 token 添加到源码仓库的 Secret
进入 blog-src → Settings → Secrets and variables → Actions → New repository secret
Name 填 GH_TOKEN(下文 workflow 里引用),Value 粘贴刚才的 token。

三、一键 workflow 文件

在源码仓库根目录新建 .github/workflows/deploy.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
35
36
37
38
39
name: Deploy to External Repo
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source repo
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Cache dependencies
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm install

- name: Build site
run: npm run build

- name: Deploy to external repo
uses: peaceiris/actions-gh-pages@v4
with:
personal_token: ${{ secrets.GH_TOKEN }} # 必须是 PAT,且对目标仓库有写权限
external_repository: lxyangfan/lxyangfan.github.io # 替换为你的目标仓库
publish_branch: gh-pages # 目标仓库的 GitHub Pages 分支
publish_dir: ./public # 构建输出目录
cname: frankk.top # 可选:自定义域名
0%