更换Cloudflare到GitHub Pages

突发奇想,Github Pages 就可以直接访问网站,那么可以不用Cloudflare了,直接用Github Pages,这样就可以省下Cloudflare的用量了。

需要改的内容如下:

  • 去掉Cloudflare原来的DNS解析
  • Github Pages设置自定义域名
  • 在域名注册商那里设置Github Pages的域名解析
  • 添加Hexo deploy配置文件,指定Github Pages的仓库地址

换起来还是有点问题。再观察观察。

更新:没问题了,配置域名域名有延迟,不要来回换仓库。下一步是配置一下Github Actions,自动部署。现在是手动部署的。

换成Github Actions自动部署过程中,遇到了各种各样的问题:
首先要写workflow的脚本。更改了几版,最后的版本如下:

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true # Checkout private submodules(themes or something else).

# Caching dependencies to speed up workflows. (GitHub will remove any cache entries that have not been accessed in over 7 days.)
- name: Cache node modules
uses: actions/cache@v3
id: cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 8
run_install: true

- name: Generate Content
run: pnpm run build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./dist

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

然后我发现我的theme主题不对……我用的theme-next/hexo-theme-next,这个已经好几年没更新了。但有个仓库是next-theme/hexo-theme-next
theme-next和next-theme……
然后我做了一下更换主题,我用的submodule的方式,要删除原本的主题,然后注意.git/config里的配置也要删掉,然后重新submodule add新的主题。
主题里还有点小问题是有个muse.js找不到,我就把schema里的muse改成Pisces

现在是把仓库的名字换成了username.github.io,之后会尝试其他的仓库名字,部署Github Pages。