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

需求#

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

![[../images/others/itdog-ping-blog.png]]

Fuwari from 2025/10/13#

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

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

Workflow 文件如下,基本上没什么变化,但是似乎编译2遍(懒得修

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 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 -- .
# 复制所有文件到../src/content/posts/
mkdir -p ../src/content/posts/
cp -r ./* ../src/content/posts/
cd ..
# 清理临时目录
rm -rf temp_posts
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install && pnpm add sharp
- name: Build blog
run: pnpm build
- name: Install Vercel CLI
run: npm install -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 --prod --token=$VERCEL_TOKEN
# Deploy 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