1. 架构设计

这套方案通过以下组件的深度协作,实现了「本地创作,云端部署」的闭环:

  • Obsidian:作为全能笔记库,通过 Git Submodule 嵌入博客源码。
  • GitHub 私有仓库:存放 Hexo 配置文件及 Markdown 原稿,确保创作隐私。
  • GitHub Actions (CI/CD):充当云端大脑,监听源码变动并自动执行环境安装、编译与发布。
  • GitHub 公共仓库:作为托管载体,仅存放编译后的静态网页文件。

2. 自动化部署配置 (CI/CD)

2.1 建立 SSH 信任链

为了让 GitHub Actions 自动向公共仓库推送代码,需配置 SSH 密钥:

  1. 生成密钥对ssh-keygen -t rsa -b 4096 -f github-deploy-key
  2. 公共仓库设置:进入 username.github.io > Settings > Deploy keys,添加公钥内容,并勾选 Allow write access
  3. 私有仓库设置:进入 hexo-blog-source > Settings > Secrets,添加私钥内容,命名为 HEXO_DEPLOY_PRI

2.2 编写自动化脚本

在私有仓库根目录下创建 .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
name: Hexo Auto Deploy
on:
push:
branches: [main]

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'npm'
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.HEXO_DEPLOY_PRI }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Deploy
run: |
npm install -g hexo-cli
npm install
hexo clean && hexo g -d

3. 深度集成 Obsidian

3.1 引入子模块

将博客源码仓库作为子模块嵌入你的 Obsidian 库中:

1
2
cd ~/your_obsidian_vault
git submodule add https://github.com/yourname/hexo-blog-source.git GitBlog

3.2 视觉净化 (File Explorer++)

为保持侧边栏纯净,仅显示文章目录,在 File Explorer++ 插件的 Hide Filter 中设置以下正则:

1
^GitBlog/(?!(source/|source$)).*|^GitBlog/source/(?!(_posts/|_posts$)).*

3.3 其他配置(可选)

  • Templater:配置给_posts下的文件自动加 post front-matter
  • Git:开启 Submodule management
  • Linter:把路径添加到 Folders to ignore
  • Files and links:把路径添加到 Advanced - Excluded Files

4. 极致写作流体验

  1. 撰写:在 Obsidian 的 GitBlog/source/_posts 目录下直接新建 Markdown。
  2. 提交:保存后 Obsidian Git 插件自动进行 Push。
  3. 生效:GitHub Actions 接收信号,自动在云端完成部署。

只要配置一次,余下的只有创作。


最后一步建议:
粘贴完成后,请记得将 yournameusername 以及 你的邮箱 替换为实际信息。然后使用 Obsidian Git 插件执行一次