LOG[2021-09-01]

LOG[2021-09-01]@v0 by GHOST, 1630426394588

没上次那么阴间了

完成了Cloudflare同步站的配置

速度还行

顺便接入了Cloudflare Analytic

中间跨域炸了好几次

最后发现是Cloudflare没自动同步的锅其实还有一点是我把仓库名写错了


LOG[2021-09-01]@v1 by GHOST, 1630431561493

大概讲一下怎么实现的

安装js-yaml

1
$ npm install js-yaml

把源码存在一个私有仓库内

ssh直接复制放在根目录

.gitignore

1
2
3
4
node_modules
.deploy_git
public
db.json

GitHub Actions像下面这么配置

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
name: Hexo Blog CI

on:
# push:
# branches:
# - master
watch:
types: [started]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository master branch
uses: actions/checkout@master

- name: Setup Node.js 16.x
uses: actions/setup-node@master
with:
node-version: "16.x"

- name: Setup Hexo Dependencies
run: |
npm install hexo-cli -g
npm install

- name: Setup Deploy Key
run: |
mkdir ~/.ssh/
cp ./.ssh/id_rsa ~/.ssh/id_rsa
cp ./.ssh/id_rsa.pub ~/.ssh/id_rsa.pub
cp ./.ssh/known_hosts ~/.ssh/known_hosts
sudo chmod 0600 ~/.ssh/id_rsa
sudo chmod 0600 ~/.ssh/id_rsa.pub
sudo chmod 0600 ~/.ssh/known_hosts

- name: Setup Git Information
run: |
git config --global user.name 'username'
git config --global user.email 'useremail'

- name: Deploy Hexo
run: |
hexo clean
hexo generate
hexo deploy

- name: Generate
run: |
node cf-pages.js
cp "./hexo-config.yml" ./_config.yml
cp "./next-config.yml" ./themes/next/_config.yml

- name: Redeploy Hexo
run: |
hexo clean
hexo generate
hexo deploy

新建一个仓库, 也就是下面的hexo_config.deploy.repo

cf-pages.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const fs = require('fs');
const yaml = require('js-yaml');

try {
let hexo_config = yaml.load(fs.readFileSync('./_config.yml', 'utf8'));
// hexo_config.url = ""
// hexo_config.deploy.repo = '';
// hexo_config.deploy.branch = "";
fs.writeFileSync('./hexo-config.yml', yaml.dump(hexo_config), 'utf8');
let next_config = yaml.load(fs.readFileSync('./themes/next/_config.yml', 'utf8'));
fs.writeFileSync('./next-config.yml', yaml.dump(next_config), 'utf8');
}
catch (e) {
console.log(e);
}

大概就这样

后面的就很简单了

Cloudflare
|
v
Pages
|
v
Create a project
|
v
branch: hexo_config.deploy.branch
Build command:
Build output directory: /
Root directory: /

等待部署完成就行了