HiSEN

Personal Technology Blog

0%

Hexo 升级 & 优化

1. 概览

换了电脑,hexo 一直没迁移。乘着周末,折腾一下。
幸好之前有一个记录可以参考一下:hexo安装过程
最新版本的 node 和 老版本的 hexo 有兼容性问题(hexo 官方说明),所以需要升级。

项目折腾前折腾后
hexo 版本3.9.07.3.0
托管GitHubCloudflare
原始域名hisenyuan.github.iohisenyuan-github-io.pages.dev

2. 过程

过程比较挫折,我就写最后的过程。
插件+主题等都需要重新安装和配置,网上都有教程。

2.1 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 安装 node
$ brew install node
# 安装 hexo (如果按官方的安装方式,最新只能安装 4.x)
$ brew install hexo
# 查看 hexo 版本
$ hexo version
INFO Validating config
hexo: 7.3.0
hexo-cli: 4.3.2
os: darwin 24.4.0 15.4.1
# 初始化新 hexo
$ hexo init blog
# 安装 git 提交插件
npm install hexo-deployer-git --save
# 安装体积缩小插件(性能优化)
npm install hexo-neat --save
# 安装图片懒加载插件
npm install hexo-lazyload-image --save

2.2 迁移数据

把旧电脑的整个 blog 拷贝到新电脑。
然后把 source 目录迁移到新初始化( hexo init blog 这步 )
confi 相关的话就看新老都 diff,看着配置==

2.3 配置主题

1
$ git clone https://github.com/theme-next/hexo-theme-next themes/next

然后在 blog 的站点配置里面修改主题 theme: next
其它的就在 next 的配置里面进行调整

2.4 迁移到 Cloudflare

Cloudflare 也有 pages 的功能。原理是授权 github 给 Cloudflare 自动拉取部署。
迁移之前: hisen.me -> Cloudflare -> github.io
迁移之后: hisen.me -> Cloudflare

具体的操作过程:

  1. 登录 Cloudflare
  2. 找到 Worker
  3. 创建
  4. Pages
  5. 导入现有 Git 存储库
  6. 授权(建议仅授权仓库)
  7. 保存并部署
  8. 可以设置域名(我这一步很顺利,因为之前就在用 Cloudflare CDN)

2.4.1 一次提交构建过程

提交:2025-07-19 16:12:08
构建:2025-07-19 16:12:40
耗时:8s

2.4.1.1 hexo 提交

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[main 5a25906] Site updated: 2025-07-19 16:12:08
601 files changed, 1271 insertions(+), 1195 deletions(-)
create mode 100644 20250719-hexo-upgrade-and-optimize/index.html
create mode 100644 archives/2025/07/index.html
create mode 100644 archives/2025/index.html
create mode 100644 tags/hexo/page/2/index.html
Enumerating objects: 2105, done.
Counting objects: 100% (2105/2105), done.
Delta compression using up to 12 threads
Compressing objects: 100% (644/644), done.
Writing objects: 100% (1227/1227), 695.41 KiB | 3.16 MiB/s, done.
Total 1227 (delta 583), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (583/583), completed with 264 local objects.
To github.com:hisenyuan/hisenyuan.github.io.git
8ee58fc..5a25906 HEAD -> master
branch 'main' set up to track 'git@github.com:hisenyuan/hisenyuan.github.io.git/master'.
INFO Deploy done: git

2.4.1.2 Cloudflare 构建

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
16:12:24.762	Cloning repository...
16:12:25.822 From https://github.com/hisenyuan/hisenyuan.github.io
16:12:25.822 * branch 5a259063ef0189af5c31801cfc15d90817c95c9b -> FETCH_HEAD
16:12:25.822
16:12:25.925 HEAD is now at 5a25906 Site updated: 2025-07-19 16:12:08
16:12:25.926
16:12:26.004
16:12:26.005 Using v2 root directory strategy
16:12:26.028 Success: Finished cloning repository files
16:12:27.685 Checking for configuration in a Wrangler configuration file (BETA)
16:12:27.686
16:12:28.794 No wrangler.toml file found. Continuing.
16:12:28.794 No build command specified. Skipping build step.
16:12:28.795 Note: No functions dir at /functions found. Skipping.
16:12:28.795 Validating asset output directory
16:12:31.586 Deploying your site to Cloudflare's global network...
16:12:33.708 Uploading... (34/635)
16:12:35.115 Uploading... (235/635)
16:12:35.117 Uploading... (435/635)
16:12:35.394 Uploading... (635/635)
16:12:35.394 ✨ Success! Uploaded 601 files (34 already uploaded) (2.00 sec)
16:12:35.394
16:12:35.827 ✨ Upload complete!
16:12:39.096 Success: Assets published!
16:12:40.432 Success: Your site was deployed!

3. 注意事项

升级了 hexo 之后(之前是 3.x)
语法上有点变化,最大就是波浪号( ~ ),如果不带空格,那么即使换行了,也会被认为是删除线。

3.1 波浪线处理前

效果源码:

1
2
我是~第一行
我是~第二行

效果预览:
我是第一行
我是
第二行

3.2 波浪线处理后

效果源码:

1
2
我是 ~ 第一行
我是 ~ 第二行

效果预览:
我是 ~ 第一行
我是 ~ 第二行