Files
HowToLiveBetter/.github/workflows/book.yml
T
Zhao Chen 14bbb39fde 检索网页、离线版、PDF 也拆超长收益、备注和来源,四个出口同一套规则
上一个提交只改了 EPUB,网页、离线单文件、PDF 上同一条收益仍是一整块。这次四个出口都拆,
正文 md 仍不动(index.html 按行解析、sync-stats 按「- 来源:」行数链接都依赖一个字段一行)。

- tools/lib/split-items.mjs:导出 splitGain / splitSrc。来源栏改用 index.html 原有 splitSrc
  的规则(括号外的「;」一条一行),四个出口的来源拆法从此一致。
- index.html:在原有 splitSrc 旁边加同一份 splitGain,收益、备注拆开时渲染成一块一行的列表,
  两份规则用 // <split-rules> 标出来。离线单文件用的是同一个 index.html,自动跟上。
- tools/pdf/build.mjs:read 之后同样套 splitLongItems。
- tools/check-split.mjs:从 index.html 抽出 <split-rules> 那段,和 split-items.mjs 在全书
  2013 个收益/备注/来源字段上逐条比对;也查拆完能否逐字拼回原文、** 有没有被拆开。
  CI 新增「拆分规则一致性检查」job,和交叉引用检查一样不挡发布。
- 换话题规则排除「该 / 本 / 此 / 这 / 同 / 上述」开头:「该办法第五条」是接着上文讲的,不另起。
- CLAUDE.md 电子版那段记一笔:规则两份要同步。

验证:check-split 0 处问题(拆开 554 个字段);check-plain、check-refs --check、
sync-stats --check 全过;epubcheck 5.4.0 0 errors / 0 warnings;pandoc 3.11 + typst 0.15.1
出 PDF 正常;本地起服务器和 file:// 打开离线单文件,第 31 节第 1 条的收益都拆成 11 行,控制台无报错。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X6s254TjQjvF9YgR8uK1LE
2026-10-08 11:48:59 +08:00

164 lines
5.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 正文一改就重新生成三样,挂到固定的 Release「epub-latest」上,下载链接不变:
# EPUB https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.epub
# PDF https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.pdf
# 离线单文件 https://github.com/eternity4719/HowToLiveBetter/releases/download/epub-latest/HowToLiveBetter.html
# PR 只生成并校验,不发布,产物在 Actions 页面的 artifact 里。
name: 电子书
on:
push:
branches: [main]
paths:
- README.md
- index.html
- og.png
- ads/**
- book/**
- docs/*.md
- tools/**
- .github/workflows/book.yml
pull_request:
paths:
- README.md
- index.html
- og.png
- ads/**
- book/**
- docs/*.md
- tools/**
- .github/workflows/book.yml
workflow_dispatch:
permissions:
contents: write
concurrency:
group: book-${{ github.ref }}
cancel-in-progress: true
env:
PANDOC_VERSION: '3.11'
TYPST_VERSION: '0.15.1'
jobs:
# 交叉引用检查。单独一个 job,不挂在 build 里:锚点没补好不该连累 EPUB、PDF 和
# 离线单文件的发布,那是两回事。PR 上照样红,main 上该发的还是发出去。
# 本地那条链路(sync-stats.mjs)要记得跑才会跑,
# 外部 PR 更是完全跑不到,所以这道检查得在 CI 里有一份。零依赖,几秒钟。
refs:
name: 交叉引用检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-refs.mjs --check
# 说人话检查:长度、研究行话、抽象说法。理由同上,单独一个 job,不挡发布。
plain:
name: 说人话检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-plain.mjs
# 拆分规则一致性检查:超长收益、备注和来源的拆分规则有两份(tools/lib/split-items.mjs 给 EPUB、PDF,
# index.html 里 <split-rules> 那段给网页和离线版),只改了一边就会四个出口长得不一样。理由同上,不挡发布。
split:
name: 拆分规则一致性检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/check-split.mjs
# 统计数字检查:README、index.html、og.html 里的条目数、A/B/C 数、链接数等是否和 book/ 对得上。
# 本地 sync-stats.mjs 要记得跑才会更新,网页上直接合并的 PR 完全经过不了它。理由同上,不挡发布。
# 只查不改:让 CI 往 main 推提交会和本地分叉,而且 Ubuntu 没有微软雅黑,og.png 截不对。
stats:
name: 统计数字检查
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: node tools/sync-stats.mjs --check
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: tools/epub/package-lock.json
- run: npm ci
working-directory: tools/epub
- name: EPUB
run: node tools/epub/build.mjs
- name: 离线单文件 HTML
run: node tools/offline/build.mjs
- name: 装 pandoc、typst 和中文字体
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends fonts-noto-cjk
curl -sSL "https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-linux-amd64.tar.gz" | tar xz
curl -sSL "https://github.com/typst/typst/releases/download/v${TYPST_VERSION}/typst-x86_64-unknown-linux-musl.tar.xz" | tar xJ
echo "$PWD/pandoc-${PANDOC_VERSION}/bin" >> "$GITHUB_PATH"
echo "$PWD/typst-x86_64-unknown-linux-musl" >> "$GITHUB_PATH"
- name: PDF
run: |
typst fonts | grep -i -E 'noto (serif|sans) cjk' || echo '没找到 Noto CJK,PDF 会退到别的字体,检查 fonts-noto-cjk 这一步'
node tools/pdf/build.mjs
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: epubcheck
run: |
curl -sSL -o epubcheck.zip https://github.com/w3c/epubcheck/releases/download/v5.4.0/epubcheck-5.4.0.zip
unzip -q epubcheck.zip
java -jar epubcheck-5.4.0/epubcheck.jar dist/HowToLiveBetter.epub
- uses: actions/upload-artifact@v4
with:
name: HowToLiveBetter
path: |
dist/HowToLiveBetter.epub
dist/HowToLiveBetter.pdf
dist/HowToLiveBetter.html
- name: 发布到 Release epub-latest
if: github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
run: |
git tag -f epub-latest
git push -f origin epub-latest
notes="正文提交 ${GITHUB_SHA::7},生成于 $(date -u -d '+8 hours' +'%Y-%m-%d %H:%M')(北京时间)。EPUB、PDF、离线单文件 HTML 三样,正文每次更新后自动重新生成,下载链接固定不变。"
if gh release view epub-latest >/dev/null 2>&1; then
gh release edit epub-latest --title "电子书(EPUB / PDF / 离线 HTML,自动更新)" --notes "$notes"
else
gh release create epub-latest --title "电子书(EPUB / PDF / 离线 HTML,自动更新)" --notes "$notes" --latest=false
fi
gh release upload epub-latest \
dist/HowToLiveBetter.epub \
dist/HowToLiveBetter.pdf \
dist/HowToLiveBetter.html --clobber