用 Hexo + 安知鱼搭一个博客,并部署到 Cloudflare Pages

环境

node -v   # v22.x
npm -v    # 10.x
git --version

初始化

npx hexo-cli init my-blog
cd my-blog
npm i hexo-theme-anzhiyu hexo-renderer-pug hexo-generator-searchdb hexo-wordcount hexo-abbrlink

改 _config.yml 里的 theme: anzhiyu,然后把主题包的 _config.yml 复制到根目录并改名 _config.anzhiyu.yml —— 这样主题升级时你的配置不会被覆盖。

必备配置项

permalink: posts/:abbrlink/
abbrlink:
  alg: crc32
  rep: hex

好处是文章标题改了 URL 也不会变,对 CDN 缓存、外部引用都友好。

站内搜索

# 站点 _config.yml
search:
  path: search.xml
  field: post
  content: true
  format: html
# _config.anzhiyu.yml
local_search:
  enable: true

搜不到东西的时候,九成是这两个没配对:一个负责生成索引,一个负责读索引。

Cloudflare Pages 构建参数

参数 值
Framework preset Hexo
Build command npm run build
Build output directory public
环境变量 NODE_VERSION 22

最坑的一点:Cloudflare 默认 Node 版本偏老,Hexo 8 跑不起来,必须显式设 NODE_VERSION。

小结

整套链路跑通之后,写文章就只剩三件事:写 Markdown、git commit、git push。剩下的自动化会替你做完。