718 字
4 分钟
Blog方案
2025-05-30

需求#

  • 全球CDN加速访问,包括国内
  • 静态托管,不会被打没有漏洞,家里维护不下线 省流:Vercel托管,IP解析到76.76.21.21

Fuwari from 2025/10/13#

迁移到Fuwari,用Astro的博客框架,整体看上去更“现代”了

同时编译流程全部放在本地Gitea,用vercel工具直接推送,甚至不用暴露任何源码。

Workflow 文件如下,基本上没什么变化

name: Build Blog
on:
push:
branches:
- posts # This workflow will be triggered when pushing to posts branch
workflow_dispatch: # Allow manual trigger
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout master branch
uses: actions/checkout@v4
with:
ref: master # 明确指定检出 master 分支(站点代码)
fetch-depth: 0 # Fetch all history so the posts branch can be fetched below
- name: Copy posts from posts branch
run: |
# 获取 posts 分支
git fetch origin posts:posts
# 创建临时目录
mkdir -p temp_posts
cd temp_posts
# 检出 posts 分支的内容
git --git-dir=../.git --work-tree=. checkout posts -- .
# 复制所有文件到 ../src/content/posts/
mkdir -p ../src/content/posts/
cp -r ./* ../src/content/posts/
cd ..
# 清理临时目录
rm -rf temp_posts
- name: Setup pnpm
uses: pnpm/action-setup@v4 # 读取 package.json 中 packageManager 字段固定版本
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm' # 缓存 pnpm store 加速 CI
- name: Install Vercel CLI
run: pnpm add -g vercel
- name: Deploy to Vercel
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: |
# Pull Vercel environment information
vercel pull --yes --environment=production --token=$VERCEL_TOKEN
# Build project (vercel build 会自行 pnpm install 并执行 astro build,产出 .vercel/output)
vercel build --prod --token=$VERCEL_TOKEN
# Deploy the prebuilt output to production
vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN

Hexo from 2025/05/30#

  • 拆分Posts路径到单独Branch,Obsidian挂Posts Branch,本地Markdown只有文章部分,写完直接推送触发编译
  • 本地Gitea Action编译->只推送静态资源到Github
  • Vercel托管,可以享受较快的国内的访问速度,感谢 Github项目提供优质cname解析 , 实际解析IP到76.76.21.21就行了

Gitea Workflow

name: Build Hexo Blog
on:
push:
branches:
- posts # This workflow will be triggered when pushing to posts branch
workflow_dispatch: # Allow manual trigger
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# - name: Clean posts directory
# run: |
# rm -rf source/*
- name: Copy posts
run: |
# 获取posts分支
git fetch origin posts:posts
# 创建临时目录
mkdir -p temp_posts
cd temp_posts
# 检出posts分支的内容
git --git-dir=../.git --work-tree=. checkout posts -- .
# 复制所有文件到source/
cp -r * ../source/
cd ..
# 清理临时目录
rm -rf temp_posts
- name: Install dependencies
run: npm install
- name: Build Hexo site
run: npx hexo generate
- name: Push to GitHub
env:
HLPJTOKEN: ${{ secrets.HLPJTOKEN }}
ACTOR: ${{ vars.GITHUBACTOR }}
REPOSITORY: ${{ vars.GITHUBREPOSITORY }}
run: |
# 克隆目标仓库
git clone "https://${ACTOR}:${HLPJTOKEN}@github.com/${REPOSITORY}.git" temp_deploy
cd temp_deploy
# 清空仓库内容(保留.git目录)
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
# 复制新生成的文件
cp -r ../public/* .
# 配置git
git config user.name "${ACTOR}"
git config user.email "${ACTOR}@users.noreply.github.com"
# 添加所有文件并提交
git add -A
git commit -m "Build: Update site content"
# 推送到main分支
git push origin HEAD:main
Blog方案
https://www.homelabproject.cc/posts/infra/blog方案/
作者
Channing He
发布于
2025-05-30
许可协议
CC BY-NC-SA 4.0