这篇文章记录本站当前使用的博客搭建方案。目标是从一台新电脑开始,搭建出一个可以长期写作、自动部署、图片自动上传的个人博客。

最终架构如下:

Typora / VS Code 写文章
↓
Hexo 生成静态页面
↓
GitHub 保存源码
↓
Vercel 自动部署
↓
Cloudflare 托管 DNS
↓
Cloudflare R2 + PicGo 作为图床

本站当前使用的服务和域名:

用途 服务
博客框架 Hexo
博客主题 Butterfly
代码仓库 GitHub
页面部署 Vercel
域名 DNS Cloudflare
图片存储 Cloudflare R2
图片上传工具 PicGo
写作工具 Typora / VS Code
主站域名 https://www.flying-hy.xyz
图床域名 https://img.flying-hy.xyz

1. 准备环境

先安装这些工具:

  • Node.js:运行 Hexo。
  • Git:管理代码和推送到 GitHub。
  • PicGo:上传图片到 R2。
  • Typora 或 VS Code:写 Markdown 文章。
  • 一个 GitHub 账号。
  • 一个 Vercel 账号。
  • 一个 Cloudflare 账号。
  • 一个自己的域名,例如 flying-hy.xyz。

检查 Node 和 Git 是否安装成功:

node -v
npm -v
git --version

2. 初始化 Hexo 博客

全局安装 Hexo 命令行工具:

npm install -g hexo-cli

创建博客项目:

hexo init blog
cd blog
npm install

启动本地预览:

npm run server

如果项目还没有 server 命令,可以直接运行:

hexo server

浏览器打开:

http://localhost:4000

能看到 Hexo 默认页面,就说明基础博客已经搭好了。

3. 安装 Butterfly 主题

安装主题:

npm install hexo-theme-butterfly

修改根目录 _config.yml:

theme: butterfly

本站当前核心站点配置大致如下:

title: flying HY
subtitle: '今天你努力了吗?'
description: '一个热爱ctf reverse的boy'
keywords: 博客, 技术, 生活,网络安全
author: HY
language: zh-CN
timezone: 'Asia/Shanghai'
url: https://www.flying-hy.xyz
permalink: :year/:month/:day/:title/
theme: butterfly

生成一次页面:

npm run build

如果没有 build 命令,可以在 package.json 里加:

{
"scripts": {
"build": "hexo generate",
"clean": "hexo clean",
"server": "hexo server",
"deploy": "hexo deploy"
}
}

4. 配置 Butterfly 导航和封面

Butterfly 的配置文件是:

_config.butterfly.yml

常用导航配置:

menu:
首页: / || fa-solid fa-home
归档: /archives/ || fa-solid fa-archive
标签: /tags/ || fa-solid fa-tags
分类: /categories/ || fa-solid fa-folder-open
说说: /shuoshuo/ || fa-solid fa-comment-dots
关于: /about/ || fa-solid fa-heart
友链: /link/ || fa-solid fa-link

页面顶图建议统一配置,避免 /tags/、/categories/ 这种列表页空白:

disable_top_img: false
default_top_img: https://img.flying-hy.xyz/img/2026/07/486f61efcfa99c13d5fd1d11d2654226.jpg
index_img: https://img.flying-hy.xyz/img/2026/07/486f61efcfa99c13d5fd1d11d2654226.jpg
archive_img: https://img.flying-hy.xyz/img/2026/07/486f61efcfa99c13d5fd1d11d2654226.jpg
tag_img: https://img.flying-hy.xyz/img/2026/07/486f61efcfa99c13d5fd1d11d2654226.jpg
category_img: https://img.flying-hy.xyz/img/2026/07/486f61efcfa99c13d5fd1d11d2654226.jpg

头像也可以放到 R2 图床:

avatar:
img: https://img.flying-hy.xyz/img/2026/07/9ff411e0dbfcdc9ac41e5813f724a04b.jpg
effect: false

5. 建 GitHub 仓库

在 GitHub 创建仓库,例如:

mshzy.github.io

本地初始化 Git:

git init
git branch -M source
git remote add origin https://github.com/mshzy/mshzy.github.io.git

第一次提交:

git add .
git commit -m "初始化博客"
git push -u origin source

如果你的网络需要代理,可以临时这样推送:

git -c http.proxy=http://127.0.0.1:7892 -c https.proxy=http://127.0.0.1:7892 push origin source

这里推荐用 source 分支保存 Hexo 源码。后面 Vercel 也监听这个分支。

6. 用 Vercel 部署博客

进入 Vercel:

https://vercel.com

操作步骤:

  1. 点击 Add New Project。
  2. 选择 GitHub 上的博客仓库。
  3. Framework 选择 Other 或让 Vercel 自动识别。
  4. Production Branch 选择 source。
  5. Build Command 填:
npm run build
  1. Output Directory 填:
public
  1. 点击 Deploy。

部署成功后,Vercel 会给一个默认域名,例如:

xxx.vercel.app

后面绑定自己的域名即可。

7. Cloudflare 托管域名 DNS

把域名添加到 Cloudflare。

Cloudflare 会给两个 NS 服务器。去域名注册商那里,把域名的 Nameserver 改成 Cloudflare 提供的 NS。

等待生效后,在 Cloudflare DNS 添加记录。

主域名可以这样配置:

类型 名称 内容
A @ 216.198.79.1
CNAME www Vercel 给出的 CNAME

实际以 Vercel 项目 Domains 页面提示为准。

建议先用灰云 DNS only 完成 Vercel 域名验证,验证通过后再按需要打开橙云代理。

8. 绑定 Vercel 自定义域名

进入 Vercel 项目:

Project -> Settings -> Domains

添加:

www.flying-hy.xyz
flying-hy.xyz

Vercel 会提示需要添加什么 DNS 记录。回到 Cloudflare 按提示配置即可。

Hexo 的 _config.yml 里也要把 url 改成正式域名:

url: https://www.flying-hy.xyz

9. 创建 Cloudflare R2 图床

进入 Cloudflare:

存储和数据库 -> R2 对象存储

创建 Bucket,例如:

blog-img

进入 Bucket 设置,找到自定义域:

Settings -> Custom Domains

添加:

img.flying-hy.xyz

注意:不要手动把 img.flying-hy.xyz CNAME 到主站。应该在 R2 的自定义域里绑定,让 Cloudflare 自动处理。

如果之前有这条错误记录:

img CNAME flying-hy.xyz

需要删除后再绑定 R2 自定义域。

10. 创建 R2 API 密钥

在 R2 页面找到:

管理 R2 API 令牌

创建 Account API Token:

权限:Object Read & Write
范围:指定 bucket
Bucket:blog-img

创建完成后保存:

Access Key ID
Secret Access Key
S3 API Endpoint

注意:Secret Access Key 只显示一次,关闭页面后就看不到了。

PicGo 里的 endpoint 应该类似:

https://<ACCOUNT_ID>.r2.cloudflarestorage.com

不要带 /blog-img。

11. 配置 PicGo 上传 R2

PicGo 安装插件:

picgo-plugin-s3-uploader

新增 S3 上传器 配置:

AccessKey ID:R2 Access Key ID
SecretAccessKey:R2 Secret Access Key
桶名:blog-img
签名区域:auto
API Endpoint:https://<ACCOUNT_ID>.r2.cloudflarestorage.com
路径风格访问:yes
校验证书:yes
ACL:留空

上传路径模板:

img/{year}/{month}/{md5}.{extName}

自定义输出 URL 模板:

https://img.flying-hy.xyz/{encodedKey}

几个关键点:

  • endpoint 不要带 bucket 名。
  • bucketName 单独填 blog-img。
  • ACL 不要填 public-read,R2 不支持传统 S3 ACL。
  • 路径风格访问 要打开。

测试上传一张图,成功后链接应该类似:

https://img.flying-hy.xyz/img/2026/07/xxxx.png

12. 配置 Typora 自动上传图片

Typora 打开:

文件 -> 偏好设置 -> 图像

建议配置:

插入图片时:上传图片
上传服务:PicGo(app)
PicGo 路径:选择 PicGo.exe

测试:

  1. 截图。
  2. 粘贴到 Typora。
  3. Typora 调用 PicGo。
  4. PicGo 上传到 R2。
  5. Markdown 自动变成远程链接。

最终文章里应该是:

![](https://img.flying-hy.xyz/img/2026/07/xxxx.png)

这样博客部署到 Vercel 后,图片不会依赖本地文件。

13. 写一篇新文章

创建文章:

hexo new post "文章标题"

或者直接在 source/_posts/ 下新建 Markdown 文件。

推荐 front matter:

---
title: 文章标题
date: 2026-07-13 22:30:00
tags: [博客]
categories: 技术笔记
description: 文章简介
cover: https://img.flying-hy.xyz/img/2026/07/xxxx.png
---

注意:文章一定要有 title,否则 Butterfly 页面里可能会显示“无标题”。

14. 自动生成文章封面

为了不用每篇文章都手动找图,可以写一个封面生成脚本。

本站使用:

npm run covers

它会:

扫描 source/_posts/*.md
只处理有 title 但没有 cover 的文章
生成 1200x630 PNG 封面
通过 PicGo 上传到 R2
把 cover 写回文章 front matter

如果要重生成已经由脚本生成过的 PNG 封面:

npm run covers -- --force-generated

注意:脚本不会覆盖原本已有的手工封面。

15. 本地构建检查

每次推送前建议先跑:

npm run build

如果构建成功,会在 public/ 目录生成静态页面。

常见问题:

问题 原因
YAML 报错 front matter 冒号后面缺空格
图片不显示 仍然引用本地路径,或者 R2 链接不可访问
页面无标题 文章没有 title
Vercel 没部署 没 push 到 Vercel 监听的分支

16. 推送并触发 Vercel 部署

正常写完文章后:

git add .
git commit -m "新增文章"
git push origin source

如果需要走代理:

git -c http.proxy=http://127.0.0.1:7892 -c https.proxy=http://127.0.0.1:7892 push origin source

推送成功后,Vercel 会自动部署。

17. 常用维护命令

本地预览:

npm run server

生成静态页面:

npm run build

清理缓存:

npm run clean

生成缺失封面:

npm run covers

查看 Git 状态:

git status

推送源码分支:

git push origin source

18. 最终写作流程

以后日常写博客的流程就是:

新建 Markdown 文章
↓
Typora 粘贴图片,自动上传到 R2
↓
npm run covers 补封面
↓
npm run build 本地检查
↓
git add / commit / push
↓
Vercel 自动部署
↓
Cloudflare 域名访问

这套方案的优点是:

  • 静态博客,不需要服务器。
  • GitHub 保存源码,方便回滚。
  • Vercel 自动部署,推送即上线。
  • Cloudflare DNS 管理域名。
  • R2 图床便宜稳定,图片不占 Git 仓库。
  • PicGo + Typora 写作体验接近“截图即上传”。

搭好之后,后续主要工作就只剩写文章和推送。