神觉晓

@shenjuexiao

神觉晓

PicGo GitHub 图床搭建

📝 笔记总结

以下可以不用看,我已经卸载 PicGo。我现在使用的是直接保存图片,上传到 GitHub 仓库,然后通过链接地址引用。

例如:

https://cdn.jsdelivr.net/gh/用户名/仓库名@分支名/文件夹/图片名

或:

https://raw.githubusercontent.com/用户名/仓库名/分支名/图片名

之前的文章:GitHub raw vs cdn

当然也可以使用 PicGo 进行 GitHub 图床设置。

PicGo 2.3.0 GitHub Config

📖 内容来源

使用 PicGo + GitHub 图床,是一种很流行的免费方案,特别适合写博客、记笔记时管理图片。本质上是让 PicGo 这个工具,把你本地的图片自动上传到 GitHub 仓库,并生成一个在线的图片链接。

🔧 创建 GitHub 仓库与 Token

首先需要在 GitHub 上创建一个用来存放图片的“图床仓库”,并生成一个访问令牌 (Token),这是 PicGo 上传图片的“钥匙”。

1. 创建公开仓库

在 GitHub 点击右上角 + 号,选择 New repository注意:仓库的可见性必须选 Public,否则图片无法被公开访问。

2. 生成 Token

点击头像 → Settings → 左下角 Developer settingsPersonal access tokensTokens (classic)Generate new token (classic)
* Note (名称):随便填一个,比如 PicGo-image
* Expiration (过期时间)建议选 No expiration(永不过期),不然过期后需要重新生成并更新配置。
* Select scopes (权限):务必勾选 repo 这个选项,这会赋予 PicGo 读写你仓库的权限。
* 点击生成后,立即复制并妥善保存这个 Token(它只显示一次)。

⚙️ 配置 PicGo

下载安装 PicGo 后,在“图床设置”里找到 GitHub 进行配置。

配置项 填写内容 备注
设定仓库名 你的GitHub用户名/仓库名 例如:zhangsan/my-image-bed
设定分支名 main 2020年后GitHub新仓库默认分支为main
设定Token 粘贴刚才保存的Token
指定存储路径 img/ (选填) 图片将上传到仓库下的img文件夹,不填则传至根目录
设定自定义域名 https://cdn.jsdelivr.net/gh/你的用户名/仓库名@main 这是最关键的一步,使用jsDelivr CDN加速访问,国内访问更快

小提示:如果上传成功后图片无法显示,大概率是“自定义域名”配置有误。可以尝试将域名改为 https://raw.githubusercontent.com/你的用户名/仓库名/main 测试。

✍️ 与 Typora 集成(可选)

如果你用 Typora 写 Markdown,可以配置它调用 PicGo 实现“粘贴即上传”:

  1. 打开 Typora,进入 文件偏好设置图像
  2. 插入图片时:选择 上传图片
  3. 上传服务:选择 PicGo (app),并指定你 PicGo 的安装路径。
  4. 点击“验证图片上传选项”,成功后就可以在 Typora 里愉快地粘贴图片了。

⚠️ 常见问题与排错

  1. Token 过期:这是最容易被忽略的问题。如果之前能用,突然有一天上传失败,可以先检查一下你的 GitHub Token 是否已过期。建议生成时直接选 No expiration
  2. 端口占用:PicGo 默认监听端口是 36677,如果同时开启了多个 PicGo 进程或其他加速工具(如 Steam++),可能会冲突,导致上传失败。
  3. 网络与 Hosts:由于 GitHub 服务器在国外,网络波动可能影响访问。如果上传很慢或失败,可以尝试修改 Hosts 文件,将 raw.githubusercontent.com 等域名指向可用 IP。

Valaxy Deploy to GitHub Pages

Valaxy 部署 GitHub Pages

📖 内容来源

✨ VALAXY
下一代静态博客框架
简洁、强大、高性能。遇见你一直想要的现代博客框架。

⚙️ 自带的 gh-pages.yml

.github/workflows/gh-pages.yml

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
# gh-pages.yml

name: GitHub Pages

on:
push:
branches:
# The branch where the project source code resides
# 项目源代码所在的分支
- main
- master
- valaxy

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [lts/*]
os: [ubuntu-latest]
fail-fast: false

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/

- name: 📦 Install Dependencies
run: npm i

- name: 🌌 Build Valaxy Blog
run: npm run build

- name: 🪤 Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
force_orphan: true

在使用 pnpm create valaxy 创建模版项目时,已内置文件 .github/workflows/gh-pages.yml 以实现 GitHub Actions 的自动部署工作流。

选择 Github Repo,打开 Settings -> Action -> General -> Workflow permissions,选择 read and write permissions
上传至 GitHub Repo,打开 Settings -> Pages,选择 gh-pages 分支。
gh-pages 已由 .github/workflows/gh-pages.yml 自动部署。

注意修改 gh-pages.yml 中的 on.push.branches 为你源代码所在的分支,默认为 main

❌ Error: Action failed

Error: Action failed with "The process ‘/usr/bin/git’ failed with exit code 128"

Valaxy Error Action failed

不知道为什么在同一个仓库使用 github_token: ${{ secrets.GITHUB_TOKEN }} 还会权限不够。

✅ 解决方案

这个错误是因为 GitHub Actions 的默认 token 权限不足,无法推送到 gh-pages 分支。以下是几种解决方案:

1:使用个人访问令牌

  • 生成 Personal Access Token

    • 前往 GitHub SettingsDeveloper settingsPersonal access tokensTokens (classic)
    • 生成新 token,勾选 repo 权限
    • 复制生成的 token
  • 在仓库中设置 Secret

    • 前往仓库 SettingsSecrets and variablesActions
    • 添加新的 secret,命名为 PERSONAL_TOKEN,值粘贴你的 token
  • 修改 workflow 文件

1
2
3
4
5
6
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.PERSONAL_TOKEN }}
publish_dir: ./dist
# 其他配置...

2:使用 GitHub 自带的 GITHUB_TOKEN

修改 workflow 文件,添加写入权限:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
name: Deploy

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
# ... 其他步骤

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist

⚠️ 补充:关于 Node 警告的解决方案

workflow 中添加环境变量:

1
2
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

或者在部署步骤中指定:

1
2
3
4
5
6
7
8
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
# 在 env 中设置
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true

如果以上方案都不行,请检查:

  1. 仓库是否属于组织?可能需要调整权限设置
  2. 是否启用了分支保护规则?需要临时禁用或配置允许强制推送

📝 修改后的 gh-pages.yml

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
# valaxy 自带 gh-pages.yml
# valaxy.site/zh/guide/deploy

name: GitHub Pages

on:
push:
branches:
# The branch where the project source code resides
# 项目源代码所在的分支
- main
- master
- valaxy

# 20260804
# 增加权限
permissions:
contents: write
pages: write
id-token: write

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
node-version: [lts/*]
os: [ubuntu-latest]
fail-fast: false

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/

- name: 📦 Install Dependencies
run: npm i

- name: 🌌 Build Valaxy Blog
run: npm run build

- name: 🪤 Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
force_orphan: true

Valaxy build lts ubuntu-lastest

hexo-theme-next add Giscus

hexo-theme-next 添加 Giscus

内容来源

在 NexT 主题中为 Hexo 博客添加 Giscus 评论系统,主要有这几个步骤:准备好 GitHub 仓库、安装 NexT 专用的 Giscus 插件,然后在主题配置文件中填入从 Giscus 官网获取的关键信息。

📝 第一步:准备工作

在开始配置前,需要先完成三项必要的 GitHub 设置,这些是所有后续操作的基础:

  1. 创建一个公开的 GitHub 仓库:Giscus 要求评论数据存放在公开仓库中。你可以用现有的博客仓库,或者为评论单独新建一个仓库。

  2. 启用仓库的 Discussions 功能:进入仓库的 Settings -> General,在 Features 部分找到并勾选 Discussions

  3. 安装 Giscus App:访问 GitHub Apps - giscus,点击安装,并选择你刚刚准备好(已公开且开启 Discussions)的仓库。

Giscus GitHub Apps giscus

⚙️ 第二步:安装与配置

1. 安装 NexT 专用插件

由于 NexT 主题本身不直接支持 Giscus,需要安装一个社区插件来集成。在博客根目录下执行以下命令:

1
npm install hexo-next-giscus --save

这个插件会负责在页面中注入 Giscus 所需的代码,并让配置能和 NexT 主题很好地结合起来。

2. 获取配置参数

安装完插件后,访问 Giscus 官网,它会引导你完成配置并生成一段 <script> 代码。

主要需要填写的几个关键信息是:

  • 仓库你的GitHub用户名/评论仓库名
  • 页面 ↔️ discussion 映射关系:对于 Hexo 博客,通常推荐选择 pathname,这样每篇文章的评论会和其 URL 路径绑定。
  • Discussion 分类:选择一个已有的分类,如 GeneralAnnouncements。建议选择 Announcements,这样新的 discussion 只能由维护者或 Giscus 创建,可以避免混乱。

Giscus giscus.app/zh-CN

配置好后,在页面最下方复制生成的代码,我们只需要从中提取几个以 data- 开头的参数值。

3. 将参数填入 NexT 配置文件

打开主题配置文件 themes/next/_config.yml(或者根目录的 _config.next.yml),在文件末尾添加或修改以下 giscus 配置块。

将上一步从 Giscus 官网复制下来的参数(如 data-repo, data-repo-id 等)对应的值填写进去,注意不要保留 data- 前缀和引号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 在 themes/next/_config.yml 文件末尾添加
giscus:
enable: true
# 用户名/仓库名,对应 data-repo
repo: 用户名/仓库名
# 仓库 ID,对应 data-repo-id
repo_id: 仓库 ID
# 选择的分类,对应 data-category
category: Announcements
# 分类ID,对应 data-category-id
category_id: 你的分类 ID
# 推荐用页面路径匹配,对应 data-mapping
mapping: pathname
# 开启表情回应
reactions_enabled: 1
emit_metadata: 0
# 评论框位置
input_position: bottom
# 建议使用自动适配主题
theme: preferred_color_scheme
# 语言设置
lang: zh-CN
# 懒加载,提升性能
loading: lazy

🚀 第三步:部署与测试

最后,重新生成并部署你的博客,就可以看到效果了:

1
hexo clean && hexo generate && hexo deploy

或者直接使用:

1
hexo server

部署成功后,打开任意一篇文章滑到底部,就能看到 Giscus 评论区了。如果页面没有显示,可以检查一下博客是否已经成功部署到线上。

Giscus shenjuexiao.com

Typecho-CF 安装部署

📄 内容来源

基于 Typecho 完整重写的现代博客系统,运行在 Astro + Cloudflare Workers + D1 之上。保留 Typecho 数据库表结构,支持从 PHP 版 Typecho 直接迁移数据。

⚙️ 前置要求

  • Node.js 18+
  • pnpm(npm install -g pnpm)
  • Wrangler CLI(npm install -g wrangler)
  • Cloudflare 帐号

💻 本地开发

1
2
3
4
5
6
7
8
9
# 克隆并安装依赖
git clone https://github.com/eslizn/typecho-cf.git
cd typecho-cf
pnpm install

# 启动开发服务器(D1 + R2 由 wrangler 自动模拟)
pnpm run dev
# 访问 http://localhost:4321
# 首次访问自动跳转安装向导

Typecho-CF pnpm run dev

❌ Error: Failed to load url path

Typecho-CF_Failed_to_Load_URL_Path

搞了半天弄不好,暂时放弃了。

记录一下,往后再折腾。

Test3

应该掌握几种编程语言

Should Master Several Programming Languages

📝 笔记总结

应该掌握几种编程语言:初学者(入门阶段),先死磕 1 门;求职/工作阶段,主攻 1 门 + 辅修 1 门;资深/架构阶段,掌握“范式”而非“语言”; 特殊领域,必须多语言。

📖 内容来源

这个问题没有标准答案,因为它完全取决于你的目标。但一个被广泛认可的准则是:精通1-2门,熟悉3-5门,了解越多越好

下面按不同职业阶段和目标,给你一个清晰的参考框架:

🎯 初学者(入门阶段):先死磕 1 门

  • 建议JavaScriptPython
  • 原因:这两门语法友好、生态强大,能让你快速做出可见的东西(网页、爬虫、小工具),建立正反馈。这个阶段最忌讳“贪多嚼不烂”,语言切换的成本会严重拖慢你对编程本质(逻辑、数据结构)的理解。
  • 目标:用这一门语言能独立写出完整的项目。

💼 求职/工作阶段:主攻 1 门 + 辅修 1 门

建议组合:

  • 前端:JavaScript/TypeScript(主) + Python/Go(辅,用于写脚本或BFF层)。
  • 后端/云原生:Java/Go(主) + Python(辅,用于自动化运维或AI粘合)。
  • 数据科学/AI:Python(主) + SQL(必会,非完整编程语言但至关重要) + C++/Rust(辅,用于优化性能)。
  • 原因:公司招聘看重深度,面试时要求你能用主力语言解决复杂工程问题。但业务场景多变,掌握一门副语言能让你不被特定技术栈卡死。

🧠 资深/架构阶段:掌握“范式”而非“语言”

到这个级别,你不再纠结语法,而是需要熟悉编程范式的三个代表:

  • 面向对象(Java/C#):用于构建大型企业级复杂系统。
  • 函数式(Scala/Clojure/Elixir):用于高并发、数据流处理。
  • 系统级/底层(C/Rust/Zig):用于理解内存、性能调优或基础设施开发。

掌握这三类范式各一门,你就具备了“用最合适的工具解决最合适的问题”的能力。

🎮 特殊领域:必须多语言

  • 全栈开发者:至少掌握 JS/TS + 一种后端语言 + SQL。
  • 嵌入式/游戏开发:C++ 是绝对核心,辅以 C 和 Lua/Python 做脚本层。
  • 区块链/智能合约:Solidity/Rust + Go/JavaScript。

⚠️ 一个关键误区需要避开

不要为了“学语言”而学语言

语言只是工具,真正值钱的是解决问题的能力。如果你能用 Python 熟练构建微服务,那么转到 Go 或 Java 只是语法和生态的迁移,通常 2-3周 就能上手,3个月 就能生产级使用。

📋 给你一个具体行动建议

  • 第1年:死磕 Python 或 JavaScript,达到熟练工水平。
  • 第2-3年:根据工作需求,补充第二语言(如 Java 或 Go),同时把 SQL 练到精通。
  • 第3年以后:按需学习,重点关注 Rust、Zig 等新兴语言,或 Kotlin、Swift 等平台语言,保持对技术趋势的敏感度。

总结一句话精通一门能吃饭,熟悉两门能防身,了解三门能开路。😊

程序员应该掌握几种编程语言

Programmer Should Master Several Programming Languages

📝 笔记总结

程序员应该掌握几种编程语言:入门/初级,1门主语言+SQL,做到精通;高级/架构,2门精通(如Java+Python)+ 1门 熟悉(如Rust/Go)+ Shell脚本;全栈/专家,3门覆盖不同范式(如TS + Go + Python),其余按需了解。

📖 内容来源

这个问题没有标准答案,但有一个被广泛认可的共识:与其纠结“几种”,不如聚焦“几个层次”

对于程序员来说,更务实的策略是 “1+N”,而不是样样通、样样松。基于2026年的技术格局,我给出一个清晰的路线图:

🎯 核心层(精通1门):安身立命之本

这一门要深到能解决内存泄漏、并发死锁、性能调优等底层问题。

  • Java/C#:企业级后端的大宗,生态极稳,适合追求长期职业安全感。
  • Go:云原生和中间件的首选,语法极简但并发模型深,适合高性能场景。
  • Python:AI和数据领域的绝对霸主,但纯后端业务逻辑用Python,长期维护成本需留意。
  • JavaScript/TypeScript:如果你专注前端或全栈,TS已是事实标准,必须精通。

🔧 辅助层(熟练1-2门):打开格局的利器

用来解决主语言不擅长的事,拓宽解决问题的思路。

  • 脚本语言(Python/Shell):自动化测试、数据处理、运维脚本,能极大提升日常效率。
  • 系统语言(Rust/C):如果你用Java/Go,学一点Rust能让你真正理解内存和指针;如果你做底层,C是绕不开的。

🧩 领域层(了解1-2门):求职的加分项

根据你的赛道来决定:

  • 做AI/数据:除了Python,SQL必须精通(这算一门“语言”),还要懂一点RScala
  • 做前端/全栈TypeScript是核心,但Rust(通过WebAssembly)或Swift/Kotlin(跨平台)会是很好的护城河。
  • 做区块链/分布式RustMove正在崛起。

🤔 关于“数量”的清醒认知

  1. 别超过3门核心:人的认知带宽有限。同时深挖3门以上不同范式的语言(如Java + Python + Rust),容易导致思维混乱,哪门都写不地道。
  2. 语言是表象,思想是内核:精通一门后,学第二门通常只需1-3个月。因为你在学的是编程范式(面向对象、函数式、并发模型),而非语法。
  3. 2026年的新变量:AI编程助手(如Copilot、Cursor)已极度成熟,它们能帮你快速“翻译”语法。现在的核心竞争力,已从“记住语法”转变为 “精准描述需求”“审查AI生成的代码”

💡 最后一个务实结论

  • 入门/初级:死磕 1门 主语言 + SQL,做到精通。
  • 高级/架构2门 精通(如Java+Python)+ 1门 熟悉(如Rust/Go)+ Shell脚本。
  • 全栈/专家3门 覆盖不同范式(如TS + Go + Python),其余按需了解。

如果现在只让我选,我会建议:TypeScript(搞定前后端统一)+ Python(搞定AI和脚本)+ 深入学习Rust(为未来5年做准备)。😊

Gmeek 部署其他仓库

📦 原有: Gmeek.yml

原有 GitHub Actions ,通过 actions/upload-pages-artifact@v3actions/deploy-pages@v4 自动化部署到本仓库的虚拟机上(注:不知这样理解是否正确)。

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: build Gmeek

on:
workflow_dispatch:
issues:
types: [opened, edited]
schedule:
- cron: \"0 16 * * *\"

jobs:
build:
name: Generate blog
runs-on: ubuntu-24.04
if: ${{ github.event.repository.owner.id == github.event.sender.id || github.event_name == 'schedule' }}
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
id: pages
uses: actions/configure-pages@v4

- name: Get config.json
run: |
echo \"====== check config.josn file ======\"
cat config.json
echo \"====== check config.josn end ======\"
sudo apt-get install jq

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Clone source code
run: |
GMEEK_VERSION=$(jq -r \".GMEEK_VERSION\" config.json)
git clone https://github.com/Meekdai/Gmeek.git /opt/Gmeek;
cd /opt/Gmeek/
lastTag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ $GMEEK_VERSION == 'last' ]; then git checkout $lastTag; else git checkout $GMEEK_VERSION; fi;

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r /opt/Gmeek/requirements.txt

- name: Generate new html
run: |
cp -r ./* /opt/Gmeek/
cd /opt/Gmeek/
python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
cp -a /opt/Gmeek/docs ${{ github.workspace }}
cp -a /opt/Gmeek/backup ${{ github.workspace }}
cp /opt/Gmeek/blogBase.json ${{ github.workspace }}

- name: update html
run: |
git config --local user.email \"$(jq -r \".email\" config.json)\"
git config --local user.name \"${{ github.repository_owner }}\"
git add .
git commit -a -m '🎉auto update by Gmeek action' || echo \"nothing to commit\"
git push || echo \"nothing to push\"
sleep 3

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

deploy:
name: Deploy blog
runs-on: ubuntu-24.04
needs: build
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: \"pages\"
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

🔧 .yml 修改需求

源仓库生成相关文件后,将静态页面 ./docs 下的文件推送到博客仓库分支 gh-pages 上,即网站部署在分支。

  • 源仓库: shenjuexiao/gmeek-source
  • 博客仓库: shenjuexiao/gmeek-docs
  • 工作流 Deploy 增加 docs 下静态页面部署到博客仓库 gh-pages 分支
  • 使用 peaceiris/actions-gh-pages
  • 跨仓库使用 token:${{ secrets.GMEEK_DOCS }}

❌ Error: HttpError: Not Found

Gmeek Deploy Setup Pages

注释掉本地的部署

1
2
3
4
# 不需要配置 GitHub Pages
# - name: Setup Pages
# id: pages
# uses: actions/configure-pages@v4
1
2
3
4
5
6
7
# 去掉源仓库的部署
# actions/upload-pages-artifact@v3 是专门为 GitHub Pages 设计的
# 创建特殊的 artifact,只能被 actions/deploy-pages@v4 使用
# - name: Upload artifact
# uses: actions/upload-pages-artifact@v3
# with:
# path: 'docs/.'
1
2
3
4
# 去掉源仓库的部署
# - name: Deploy to GitHub Pages
# id: deployment
# uses: actions/deploy-pages@v4

🔑 Error: Action failed with "not found deploy key for tokens"

Gmeek Deploy docs to

源仓库需要设置 token

  • 创建 GitHub 个人访问令牌 PAT Personal access tokens (classic)
    GitHub 头像,Settings -> Developer settings -> Personal access tokens -> Tokens (classic)
    新建 Token,勾选权限:repo(全部仓库读写权限)。
    复制生成的 Token(仅展示一次,丢失需重建)。
  • 仓库配置 Repository secrets
    仓库首页, Settings -> Secrets and variables -> Actions -> New repository secret
    Name:GH_TOKEN。
    Value:粘贴上面的 PAT。

✅ 修改后 gmeek-docs.yml

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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: build Gmeek

on:
workflow_dispatch:
issues:
types: [opened, edited]
# schedule:
# - cron: \"0 16 * * *\"

jobs:
build:
name: Generate blog
runs-on: ubuntu-24.04
if: ${{ github.event.repository.owner.id == github.event.sender.id || github.event_name == 'schedule' }}
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get config.json
run: |
echo \"====== check config.josn file ======\"
cat config.json
echo \"====== check config.josn end ======\"
sudo apt-get install jq

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Clone source code
run: |
GMEEK_VERSION=$(jq -r \".GMEEK_VERSION\" config.json)
git clone https://github.com/Meekdai/Gmeek.git /opt/Gmeek;
cd /opt/Gmeek/
lastTag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ $GMEEK_VERSION == 'last' ]; then git checkout $lastTag; else git checkout $GMEEK_VERSION; fi;

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r /opt/Gmeek/requirements.txt

- name: Generate new html
run: |
cp -r ./* /opt/Gmeek/
cd /opt/Gmeek/
python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
cp -a /opt/Gmeek/docs ${{ github.workspace }}
cp -a /opt/Gmeek/backup ${{ github.workspace }}
cp /opt/Gmeek/blogBase.json ${{ github.workspace }}

- name: update html
run: |
git config --local user.email \"$(jq -r \".email\" config.json)\"
git config --local user.name \"${{ github.repository_owner }}\"
git add .
git commit -a -m '🎉auto update by Gmeek action' || echo \"nothing to commit\"
git push || echo \"nothing to push\"
sleep 3

# 生成 HTML 后立即将 docs 文件夹上传为 artifact
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: docs
path: ${{ github.workspace }}/docs
# 设置保留 1 天,节省存储空间
retention-days: 1

deploy:
name: Deploy blog
runs-on: ubuntu-24.04
needs: build
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: \"pages\"
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# 先下载 build job 上传的 docs artifact,下载到 ./docs 目录
- name: Download docs artifact
uses: actions/download-artifact@v4
with:
name: docs
path: ./docs

# 新增:部署 docs 到博客仓库的gh-pages分支
- name: Deploy docs to gmeek-docs gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GMEEK_DOCS }}
external_repository: shenjuexiao/gmeek-docs
publish_branch: gh-pages
publish_dir: ./docs
commit_message: '🚀 Deploy static pages to gh-pages'
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
keep_files: false
force_orphan: false

GitHub CNAME 的作用

📄 内容来源

GitHub仓库里的CNAME文件,核心作用是告诉GitHub Pages服务器,当用户通过你的自定义域名(比如 www.example.com)访问时,应该展示哪个仓库的网站内容

你可以把它理解为在GitHub内部为你的域名和特定仓库建立的一个“认领”和“关联”关系。它需要在你的域名解析服务商(如阿里云、Cloudflare)设置的DNS解析配合下才能正常工作。

⚙️ 如何工作

当用户在浏览器输入你的自定义域名(如 www.example.com)并访问时,流程如下:

  1. DNS解析:用户的请求首先会去DNS服务器查询www.example.com指向哪里。你需要在DNS服务商那里添加一条 CNAME记录,将 www.example.com 指向 你的用户名.github.io。这一步把域名指向了GitHub的服务器。
  2. 请求到达GitHub:请求到达GitHub的服务器后,服务器需要知道这个请求是给哪个仓库的。
  3. 读取CNAME文件:此时,GitHub会检查所有启用了Pages的仓库,寻找根目录下名为CNAME必须大写)的文件。
  4. 匹配与响应:当GitHub在你的仓库里找到的CNAME文件内容(例如www.example.com),与用户请求的域名完全匹配时,它就知道要把这个仓库的网站内容返回给用户了。

🌐 仓库和服务商 CNAME 比较

两者的关系:分工明确的“钥匙”与“路标”。这两者缺一不可,它们共同完成从“自定义域名”到“具体 GitHub 仓库”的映射。

组成部分 作用概括 配置位置 关键点
仓库 CNAME 文件 “钥匙”:授权并告诉 GitHub,哪个域名可以访问这个仓库 仓库根目录下的 CNAME 文件 内容必须与 DNS 记录的子域名一致,且只能有一个域名
DNS CNAME 记录 “路标”:将互联网流量从你的域名指向 GitHub 服务器 域名注册商/DNS 服务商的管理后台 通常用于 www 子域名,指向<用户名>.github.io

📌 重要补充

  • 安全与唯一性:这个文件也是一种安全机制,确保只有你(仓库所有者)能决定哪个域名可以访问你的网站。如果一个域名已经被某个仓库的CNAME文件“占用”了,其他仓库就无法再使用该域名,除非你将其删除。
  • 避免使用通配符:切记不要在你的DNS服务商处为GitHub Pages设置通配符记录(如 *.example.com)。因为任何GitHub用户都可以在自己的仓库里创建一个指向你任意子域名的CNAME文件,从而可能“劫持”你的子域名来托管他们的内容。
  • 多域名支持:一个CNAME文件中只能包含一个域名。如果你想把多个域名都指向同一个网站,可以通过你的DNS服务商设置URL转发或使用其他DNS记录来实现。
  • 静态站点生成器注意事项:如果你使用Hexo、Hugo等静态站点生成器,建议将CNAME文件放在项目的源文件夹(如source目录)下。这样每次部署时,它就会被自动复制到生成的public文件夹并推送到GitHub,避免每次部署后CNAME文件丢失的问题。
  • Apex 根域名:需要注意,对于 example.com 这样的根域名(也叫 Apex 域),由于 DNS 规范限制,不能使用 CNAME 记录。你需要配置 A 记录,将其指向 GitHub 的固定 IP 地址(185.199.108.153 等四个 IP),才能实现根域名的访问。不过,这并不影响在仓库中依然需要一个内容为 example.com 的 CNAME 文件来完成授权。

Astro 安装及 GitHub Actions 自动部署

📄 内容来源

🛠️ 通过 CLI 向导安装

docs.astro.build/zh-cn/install-and-setup/

我选择的是 Astro Use blog template,也可以选择其他的选项,使用模板能快速建立页面。

Astro Use blog template

1
2
# 使用 npm 创建一个新项目
npm create astro@latest

1
2
# 使用 pnpm 创建一个新项目
pnpm create astro@latest

1
2
# 使用 yarn 创建一个新项目
yarn create astro

npm create astro@latest

📁 目录和文件

docs.astro.build/zh-cn/basics/project-structure/

Astro 采用一套约定俗成的文件夹布局来管理项目。每个 Astro 项目的根目录下都应该包括以下目录和文件:

  • src/* - 你的项目源代码(组件、页面、样式、图片等)。
  • public/* - 你的非代码、未处理的资源(字体、图标等)。
  • package.json - 项目清单。
  • astro.config.mjs - Astro 配置文件(推荐)。
  • tsconfig.json - TypeScript 配置文件(推荐)。

🚀 启动 Astro 开发服务器

docs.astro.build/zh-cn/develop-and-build/

Astro 自带了一个内置的开发服务器,它包含了项目开发所需的一切。astro dev CLI 命令将启动本地开发服务器,让你第一次看到你的新网站。

每个起始模板都预配置了一个脚本,该脚本将为你运行 astro dev。在进入你的项目目录后,使用你喜欢的包管理器运行此命令并启动 Astro 开发服务器。

1
npm run dev

1
pnpm run dev

1
yarn run dev

🌐 部署你的 Astro 站点至 GitHub Pages

docs.astro.build/zh-cn/guides/deploy/github/

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
name: Deploy to GitHub Pages

on:
# 每次推送到 `main` 分支时触发这个“工作流程”
# 如果你使用了别的分支名,请按需将 `main` 替换成你的分支名
push:
branches: [ main ]
# 允许你在 GitHub 上的 Actions 标签中手动触发此“工作流程”
workflow_dispatch:

# 允许 job 克隆 repo 并创建一个 page deployment

```yaml
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout your repository using git
uses: actions/checkout@v5
- name: Install, build, and upload your site
uses: withastro/action@v5
# with:
# path: . # 存储库中 Astro 项目的根位置。(可选)
# node-version: 20 # 用于构建站点的特定 Node.js 版本,默认为 20。(可选)
# package-manager: pnpm@latest # 应使用哪个 Node.js 包管理器来安装依赖项和构建站点。会根据存储库中的 lockfile 自动检测。(可选)
# build-cmd: pnpm run build # 用于构建你的网站的命令。默认运行软件包的构建脚本或任务。(可选)
# env:
# PUBLIC_POKEAPI: 'https://pokeapi.co/api/v2' # 对变量值使用单引号。(可选)

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

❌ Error: Failed to create deployment (status: 404)

Astro Deploy to GitHub Pages

这个错误表明 GitHub Pages 部署失败,主要原因是 GitHub Pages 没有在仓库设置中启用。错误信息明确指出:

Ensure GitHub Pages has been enabled: https://github.com/shenjuexiao/astro/settings/pages

0%