很久都没有折腾博客了,在考完研的暑假装了 openclaw 之后打算小小升级一下。

工作流升级

之前:单仓库时代

📁 本地电脑 D:\...\Blog
├── _config.yml ← 源码(无版本管理 ❌)
├── source/_posts/ ← 文章源码
├── themes/ ← 主题源码
├── node_modules/ ← 依赖
└── .deploy_git ──→ human6sa.github.io(部署仓库)

手动:hexo g && hexo d

工作流: 只能在本地写文章 → 跑 hexo g && hexo d 推到 GitHub Pages,改个主题都要小心翼翼,生怕崩了没处回退。

现在:双仓库(源码 + 部署分离)

📁 本地电脑 D:\...\Blog (Git 仓库 → blog-source)
├── _config.yml ← 源码有版本管理 ✅
├── source/_posts/ ← 文章有版本管理 ✅
├── themes/ ← 主题有版本管理 ✅
├── .git ─────→ github.com/Human6sa/blog-source(私有库)
│ ↑
│ git push
│ ↓
└── GitHub Actions 自动跑:
npm ci → hexo generate → deploy

human6sa.github.io(部署库,全是静态文件)

工作流: 写好文章 → git push 就完事,Actions 自动部署,省心。

写文章 → git push 到 blog-source 仓库

GitHub Actions 自动触发

actions/checkout 拉取源码

npm ci 安装依赖(含 hexo、butterfly 主题等)

npx hexo generate 生成静态页面

peaceiris/actions-gh-pages 推送到 human6sa.github.io

🌐 博客更新上线

deploy.yml

name: '🚀 Deploy to GitHub Pages'

on:
push:
branches: [main] # ← 触发器

jobs:
build-and-deploy:
runs-on: ubuntu-latest # ← 运行环境
steps:
- name: Checkout source
uses: actions/checkout@v4

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

- name: Install dependencies
run: npm ci

- name: Generate static files
run: npx hexo generate

- name: Deploy to human6sa.github.io
uses: peaceiris/actions-gh-pages@v3
with:
external_repository: Human6sa/human6sa.github.io
publish_branch: master
publish_dir: ./public
personal_token: ${{ secrets.DEPLOY_TOKEN }}

日常推送命令

完整版(查看 → 暂存 → 提交 → 推送):

cd D:\Coding\Blog
git status
git add -A
git commit -m "这里写你改了啥"
git push

简化版(一条龙):

cd D:\Coding\Blog
git add -A && git commit -m "更新内容" && git push

首页布局修改

之前首页文章卡片是一列排下来,内容多了显得冗长。改成两列网格布局,阅读体验好多了。

/* 首页文章卡片:两列网格 */
#recent-posts {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20px;
}

#recent-posts > .recent-post-item {
display: flex;
flex-direction: column;
height: auto;
margin-top: 0 !important;
}

#recent-posts > .recent-post-item .post_cover {
width: 100%;
height: 220px;
}

#recent-posts > .recent-post-item .post_cover img.post_bg {
object-fit: cover;
height: 100%;
width: 100%;
}

#recent-posts > .recent-post-item > .recent-post-info {
width: 100%;
padding: 20px;
}

/* 手机端:恢复一列 */
@media screen and (max-width: 768px) {
#recent-posts {
grid-template-columns: 1fr;
}
}

GitHub 仓库做图床 + jsDelivr CDN

之前在文章里引用图片要么用本地路径(部署后失效),要么找第三方图床(担心跑路)。现在直接用 GitHub 仓库做图床,配合 jsDelivr CDN,稳。

blog-source 仓库里建个 images/ 目录,图片 push 上去后直接用 CDN 链接引用:

https://cdn.jsdelivr.net/gh/Human6sa/blog-source/images/xxx.webp

文章封面引用示例:

cover: https://cdn.jsdelivr.net/gh/Human6sa/blog-source/images/Bing/AnzaBorregoBloom.webp

以上就是这次博客升级的主要改动。总结一下:

  • ✅ 工作流从手动部署变为 push 即部署
  • ✅ 源码全版本管理,改坏了也不慌
  • ✅ 首页排版更舒服
  • ✅ 图片托管自建,不再依赖第三方图床

接下来打算折腾下评论区和其他小功能,慢慢来 🐱