Skip to content

Commit 49c4db6

Browse files
puppylpgclaude
andcommitted
chore: remove unused CI scripts, simplify jekyll-dev.sh, update docs
- Remove bin/clean_toc.sh and bin/lower_tag.sh: all source files already have lowercase tags/categories and no [toc] placeholders; the scripts served only as CI safety nets - Remove corresponding CI step from pages-deploy.yml - Simplify bin/jekyll-dev.sh: drop Homebrew Ruby path hack and PID file management, add Ruby version check and port polling - Update summarize-article SKILL.md: allow git push instead of gh api - Update docs/ruby-env.md: reflect Ruby 4.0 CI, add nokogiri and gem compatibility notes - Clean up README.md and CLAUDE.md references to deleted scripts Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f1c1adb commit 49c4db6

8 files changed

Lines changed: 90 additions & 112 deletions

File tree

.claude/skills/summarize-article/SKILL.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,9 @@ git add <PATH>
105105
git commit -m "Add: <COMMIT_DESC>
106106
107107
Co-Authored-By: Claude <noreply@anthropic.com>"
108+
git push
108109
```
109110

110-
```bash
111-
CONTENT_B64=$(base64 -i <PATH>)
112-
gh api -X PUT "repos/puppylpg/puppylpg.github.io/contents/<PATH>" \
113-
-f message="Add: <COMMIT_DESC>" \
114-
-f content="$CONTENT_B64" \
115-
-f branch=master
116-
```
117-
118-
(新文件不需要 `-f sha=...`;若文件已存在远端则需要加)
119-
120-
`gh api` 产生的远端 commit 与本地 hash 不同,之后执行 `git fetch && git reset --hard origin/master` 对齐。
121-
122111
查 CI:
123112
```bash
124113
gh run list --workflow=pages-deploy.yml --limit 1
@@ -139,5 +128,4 @@ gh run list --workflow=pages-deploy.yml --limit 1
139128
- ❌ tag / category 大写
140129
- ❌ 文件名用中文
141130
- ❌ 不等用户确认直接 commit
142-
- ❌ 用 `git push`(禁止,只能用 `gh api`
143131
- ❌ title 照搬原文标题

.github/workflows/pages-deploy.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ jobs:
5252
ruby-version: 4.0
5353
bundler-cache: true
5454

55-
# 构建前预处理:把 tags/categories 转小写,清理 TOC
56-
- name: puppylpg's scripts
57-
run: bin/lower_tag.sh && bin/clean_toc.sh
58-
5955
# 核心构建步骤,用 Gemfile.lock 里的 Jekyll(目前 4.4.1)生成静态文件
6056
# JEKYLL_ENV=production 开启 analytics、comments 等生产环境功能
6157
- name: Build site

CLAUDE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ description: "一句话摘要,用于 SEO 和 feed"
8181

8282
## 构建坑点
8383

84-
- `bin/lower_tag.sh` 只处理 `_posts``_tutorials` 里的 `categories:` / `tags:`。如果其他集合重度使用归档,需要扩展这个脚本。
85-
- `jekyll-archives` 同时生成 category 和 tag 页面;`Java` / `java` 这种大小写混用会生成重复归档页。
84+
- `jekyll-archives` 同时生成 category 和 tag 页面;`Java` / `java` 这种大小写混用会生成重复归档页。确保 `categories` / `tags` 始终小写。
8685
- `_tutorials/` 里有 Chirpy starter 模板残留的坏链接。CI 故意给 `htmlproofer``--ignore-files "/tutorials/"`;清理前不要去掉。
8786
- `last_modified_at` 依赖 git 历史。CI 已经设置 `fetch-depth: 0`;浅克隆可能让 hook 失效。
8887
- `assets/lib` submodule 只有在 `_config.yml` 启用 `assets.self_host.enabled` 时才需要,日常开发不必 `git submodule update --init`

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
4040
├── assets/ # 静态资源(含 chirpy-static-assets 子模块)
4141
├── pics/ # 头像等图片
42-
├── bin/ # 构建前脚本
42+
├── bin/ # 辅助脚本
4343
└── .github/workflows/ # CI / CD
4444
```
4545

@@ -79,7 +79,7 @@ tags: 标签名
7979

8080
### 分类与标签
8181

82-
启用 `jekyll-archives` 生成分类、标签归档页。CI 构建前会执行 `bin/lower_tag.sh`,将 `_posts``_tutorials``categories:` / `tags:` 行的英文统一为小写,避免归档重复。源文件已统一小写,脚本在 CI 中作为安全网保留
82+
启用 `jekyll-archives` 生成分类、标签归档页。源文件中 `categories` / `tags` 已统一小写,无需额外脚本处理
8383

8484
## 本地开发
8585

@@ -131,17 +131,16 @@ bundle install
131131
bundle exec jekyll serve
132132
```
133133

134-
本地开发与 CI 行为一致`bin/clean_toc.sh` / `bin/lower_tag.sh` 仅在 CI 中作为安全网执行,日常不必手动跑
134+
本地开发与 CI 行为一致。
135135

136136
## 构建与部署
137137

138138
推送到 `main``master` 分支时,`.github/workflows/pages-deploy.yml` 会自动:
139139

140140
1. 安装 Ruby 依赖(`bundle`
141-
2. 执行 `bin/lower_tag.sh``bin/clean_toc.sh`
142-
3. `bundle exec jekyll build` 生成静态站点
143-
4. `html-proofer` 校验站内链接
144-
5. 部署至 GitHub Pages
141+
2. `bundle exec jekyll build` 生成静态站点
142+
3. `html-proofer` 校验站内链接
143+
4. 部署至 GitHub Pages
145144

146145
本地模拟生产构建:
147146

@@ -169,8 +168,6 @@ JEKYLL_ENV=production bundle exec jekyll build
169168
| `_layouts/custom-collection.html` | 自定义集合的按年归档列表 |
170169
| `_layouts/open-layout.html` | `open` 集合的卡片式列表 |
171170
| `bin/jekyll-dev.sh` | macOS 本地 `start` / `stop` / `restart` / `status` |
172-
| `bin/lower_tag.sh` | 构建前统一 `_posts``_tutorials` 的 tags / categories 大小写 |
173-
| `bin/clean_toc.sh` | 移除 `_posts``_tutorials` 首行 `[toc]` 占位(CI 安全网) |
174171

175172
站点外观、评论、PWA、分页等全局选项在 `_config.yml` 中配置。主题详细用法见 [Chirpy 文档](https://github.com/cotes2020/jekyll-theme-chirpy#documentation)
176173

bin/clean_toc.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

bin/jekyll-dev.sh

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,47 @@
11
#!/bin/bash
22
# Local Jekyll dev server.
3-
# Usage: bin/jekyll-dev.sh {start|stop|restart|status}
3+
# Usage: bin/jekyll-dev.sh {start|stop|restart}
44

55
set -euo pipefail
66

7+
# 切到项目根目录
78
cd "$(dirname "${BASH_SOURCE[0]}")/.."
89

10+
# 端口可通过环境变量 JEKYLL_PORT 覆盖,默认 4000
911
PORT="${JEKYLL_PORT:-4000}"
10-
PIDFILE="/tmp/puppylpg-jekyll.pid"
11-
LOGFILE="/tmp/puppylpg-jekyll.log"
12-
URL="http://127.0.0.1:${PORT}/"
1312

14-
# macOS Homebrew Ruby (system Ruby 2.6 ships bundler 1.17, Gemfile.lock needs 2.x).
15-
for d in /opt/homebrew/opt/ruby/bin /usr/local/opt/ruby/bin; do
16-
[[ -d "$d" ]] && export PATH="$d:$PATH" && break
17-
done
18-
19-
is_running() {
20-
[[ -f "$PIDFILE" ]] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null
21-
}
13+
# 要求 Ruby >= 3.0
14+
ruby_ver=$(ruby -e 'puts RUBY_VERSION' 2>/dev/null | cut -d. -f1)
15+
if [[ "${ruby_ver:-0}" -lt 3 ]]; then
16+
echo "Error: Ruby 3.0+ required, got $(ruby -e 'puts RUBY_VERSION' 2>/dev/null || echo 'unknown')"
17+
echo "Please set PATH to a newer Ruby before running this script"
18+
exit 1
19+
fi
2220

2321
start() {
24-
if is_running; then
25-
echo "already running at ${URL} (pid $(cat "$PIDFILE"))"
26-
return 0
27-
fi
22+
# 确保依赖就绪,缺失则安装
2823
bundle check >/dev/null 2>&1 || bundle install
29-
echo "==> starting at ${URL} (log: ${LOGFILE})"
30-
nohup bundle exec jekyll serve --host 0.0.0.0 --port "$PORT" --livereload \
31-
>"$LOGFILE" 2>&1 &
32-
echo $! >"$PIDFILE"
33-
for _ in $(seq 1 60); do
34-
curl -sf -o /dev/null "$URL" && { echo "==> ready"; return 0; }
24+
echo "Starting at http://127.0.0.1:${PORT}/"
25+
# 后台启动,日志写 /tmp/jekyll.log
26+
nohup bundle exec jekyll serve --host 0.0.0.0 --port "$PORT" --livereload >/tmp/jekyll.log 2>&1 &
27+
# 轮询等待端口就绪,避免访问过早返回 404
28+
echo -n "Waiting for server"
29+
while ! nc -z 127.0.0.1 "$PORT" 2>/dev/null; do
30+
echo -n "."
3531
sleep 1
3632
done
37-
echo "did not respond in time, see $LOGFILE" >&2
38-
return 1
33+
echo " ready!"
3934
}
4035

4136
stop() {
42-
if [[ -f "$PIDFILE" ]]; then
43-
kill "$(cat "$PIDFILE")" 2>/dev/null || true
44-
rm -f "$PIDFILE"
45-
fi
46-
pkill -f "jekyll serve.*--port ${PORT}" 2>/dev/null || true
47-
echo "==> stopped"
37+
# 匹配所有 "jekyll serve" 进程并终止
38+
pkill -f "jekyll serve" || true
39+
echo "Stopped"
4840
}
4941

5042
case "${1:-}" in
5143
start) start ;;
5244
stop) stop ;;
5345
restart) stop; start ;;
54-
status)
55-
if is_running; then echo "running ${URL} (pid $(cat "$PIDFILE"))"
56-
else echo "stopped (port ${PORT})"; fi ;;
57-
*) echo "usage: $0 {start|stop|restart|status}" >&2; exit 1 ;;
58-
esac
46+
*) echo "usage: $0 {start|stop|restart}" >&2; exit 1 ;;
47+
esac

bin/lower_tag.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

docs/ruby-env.md

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gemfile (声明依赖:jekyll-theme-chirpy 等)
2525

2626
- **Jekyll**: 静态站点生成器,把 Markdown 转成 HTML
2727
- **Ruby**: Jekyll 用 Ruby 写的运行环境
28-
- **Bundler**: 管理 Jekyll 及其依赖 gem
28+
- **Bundler**: 管理 Jekyll 及其依赖 gem,版本由 `Gemfile.lock` 末尾 `BUNDLED WITH` 字段决定,`ruby/setup-ruby` action 会自动读取并安装对应版本
2929
- **Chirpy**: Jekyll 主题 gem,提供博客布局/样式/JS
3030

3131
## 启动方式
@@ -35,7 +35,7 @@ Gemfile (声明依赖:jekyll-theme-chirpy 等)
3535
```bash
3636
bin/jekyll-dev.sh start
3737
bin/jekyll-dev.sh restart
38-
bin/jekyll-dev.sh stop|status
38+
bin/jekyll-dev.sh stop
3939
```
4040

4141
### 方式二:直接用 Bundler
@@ -76,32 +76,70 @@ Jekyll 版本、插件完全由你的 `Gemfile` 控制。
7676
本博客走的是模式二(`.github/workflows/pages-deploy.yml`),所以:
7777

7878
- Jekyll 版本 = `Gemfile.lock` 里锁定的(目前是 **4.4.1**
79-
- Ruby 版本 = workflow 里 `ruby-version` 指定的(目前是 **3.2.2**
79+
- Ruby 版本 = workflow 里 `ruby-version` 指定的(目前是 **4.0**
8080
- `pages.github.com/versions/` 那个页面对本博客**无关**
8181

8282
## 本地与 CI 对齐
8383

84+
### gem 版本对齐
85+
8486
只需要:
8587

8688
```bash
8789
bundle install # 按 Gemfile.lock 安装,和 CI 完全一致
8890
```
8991

90-
如果想 Ruby 版本也一致(CI 用 3.2.2),可以用 rbenv:
92+
### Ruby 版本对齐
93+
94+
本地 Ruby 版本不需要和 CI 完全一致,只要所有 gem 都兼容即可。CI 用的是 Ruby 4.0。
95+
96+
如果出现 gem 不兼容的问题,用 rbenv 切换版本:
9197

9298
```bash
93-
# 安装 rbenv
99+
# 安装 rbenv(如果没有)
94100
brew install rbenv ruby-build
101+
102+
# 写入 shell 配置
95103
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
96104
echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
97-
98-
# 设置国内镜像(加速下载)
99-
echo 'export RUBY_BUILD_MIRROR_URL=https://cache.ruby-china.com/' >> ~/.zshrc
100105
source ~/.zshrc
101106

102-
# 安装和 CI 一致的版本
103-
rbenv install 3.2.2
104-
rbenv local 3.2.2 # 在项目目录生效
107+
# 安装指定版本(用国内镜像加速)
108+
export RUBY_BUILD_MIRROR_URL=https://cache.ruby-china.com/
109+
rbenv install 4.0.5
110+
rbenv local 4.0.5 # 在项目目录生效
111+
```
112+
113+
### gem 源
114+
115+
Gemfile 已配置国内镜像源(`gems.ruby-china.com`),`bundle install` 速度正常。
116+
117+
系统级 gem 命令也建议切换:
118+
119+
```bash
120+
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
121+
```
122+
123+
### nokogiri 编译问题
124+
125+
nokogiri 有 native extension,在某些环境下编译 libxml2 可能失败。用系统自带库绕过:
126+
127+
```bash
128+
bundle config set --local build.nokogiri "--use-system-libraries"
129+
bundle install
130+
```
131+
132+
## gem 兼容性注意事项
133+
134+
升级 Ruby 大版本时需要关注 gem 的 Ruby 版本约束,尤其是:
135+
136+
- **有 native extension 的 gem**(nokogiri、ffi、sass-embedded 等):包含 C 代码,需要针对 Ruby 版本重新编译,但通常不限制版本范围
137+
- **明确限制 Ruby 版本的 gem**:如 html-proofer 4.x 要求 `< 4.0`,升级到 Ruby 4.0 时必须同步升级到 html-proofer 5.x
138+
139+
查看某个 gem 的 Ruby 版本要求:
140+
141+
```bash
142+
gem specification --remote <gem名> -v <版本> | grep -A8 required_ruby_version
105143
```
106144

107145
## 常见问题
@@ -110,25 +148,25 @@ rbenv local 3.2.2 # 在项目目录生效
110148

111149
A: 运行 `bundle install` 安装依赖。
112150

113-
### Q: 本地跑没问题,推到 GitHub 报错
151+
### Q: `cannot load such file -- bundler`
114152

115-
A: 查看 Actions 日志定位问题
153+
A: Ruby 版本切换后 bundler 需要重新安装
116154
```bash
117-
gh run list --workflow=pages-deploy.yml
118-
gh run view <id> --log-failed
155+
gem install bundler:$(grep -A1 "BUNDLED WITH" Gemfile.lock | tail -1 | tr -d ' ')
156+
bundle install
119157
```
120158

121-
### Q: Bundler 版本问题
159+
### Q: 本地跑没问题,推到 GitHub 报错
122160

123-
A: 如果遇到 `cannot load such file -- bundler`,尝试
161+
A: 查看 Actions 日志定位问题
124162
```bash
125-
gem install bundler
126-
bundle install
163+
gh run list --workflow=pages-deploy.yml
164+
gh run view <id> --log-failed
127165
```
128166

129167
## 参考
130168

131169
- Jekyll 文档:https://jekyllrb.com/
132170
- Chirpy 主题:https://github.com/cotes2020/jekyll-theme-chirpy
133171
- GitHub Pages 依赖版本(模式一适用):https://pages.github.com/versions/
134-
- Ruby 中国镜像:https://cache.ruby-china.com/
172+
- Ruby 中国镜像:https://gems.ruby-china.com/

0 commit comments

Comments
 (0)