hexo部署到cloudflare pages

目的

部署hexo生成静态网站信息到cloudflare pages上,自定义域名实现访问。

env

  • hexo + theme-next
  • cloudflare-page
  • wrangler

worker-sdk(wrangler)

1. 安装wrangler cli (cloudflare work-sdk)

1.1 npm install -g wrangler

➜  ~ git:(main) ✗ npm install -g wrangler
npm warn deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
npm warn deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.

added 172 packages in 16s

13 packages are looking for funding
  run `npm fund` for details

1.2 wrangler login

如果web上登录wrangler,自动oauther,点击allow

➜  ~ git:(main) ✗ wrangler login

 ⛅️ wrangler 3.101.0
--------------------

Attempting to login via OAuth...

allow
登录成功如下图:
6ddbe616edc5ae447f28a25c2fa3d00a.png

2.部署

2.1 hexo deploy (生成静态页面,存在./public目录下)

408587bc18476ac5a2c1cc572c9a9163.png

2.2推送项目

npx wrangler pages publish 接项目(生成静态资源文件)所在目录

如:
npx wrangler pages publish public/ #推送项目

后续支持命令wrangler pages deploy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  joplin-blog git:(main) ✗ npx wrangler pages publish public 
▲ [WARNING] `wrangler pages publish` is deprecated and will be removed in the next major version.

Please use `wrangler pages deploy` instead, which accepts exactly the same arguments.


✔ Enter the name of your new project: … joplin-gaga
✔ Enter the production branch name: … main
✨ Successfully created the 'joplin-gaga' project.
▲ [WARNING] Warning: Your working directory is a git repo and has uncommitted changes

To silence this warning, pass in --commit-dirty=true


✨ Success! Uploaded 370 files (22.37 sec)

🌎 Deploying...
✨ Deployment complete! Take a peek over at https://xxx.xxxx.pages.dev

第一次需要创建项目名称,看到 Success 标识推送成功

2.3 自定义域名访问

登录cloudflare -> compute(workers) -> workers和pages -> 点击项目 -> 自定义域名

5f92fad83b732e10c48efda7ff99011e.png

7964579f7cb70ddc393e75bcb8272049.png

最终实现效果:

e99030fe0db53adcaaf6974c2613cb9b.png

2.4clouflare pages免费限制

9fa571fc0418a9cc8e01a4a18cf753e7.png

免费计划将 Workers 和 Pages Functions 的请求合并。对 Workers 和 Pages 上的静态资产的请求将继续免费,且无数量限制。

美滋滋,感谢cloudflare

bd444d63f8cf8770bec8bd302f4e04e3.png