Files
claude-howto/zh/scripts/README.md
Luong NGUYEN 0e0115935d refactor(scripts): replace Mermaid.js with Pele for diagrams (#197)
* refactor(website): render diagrams with pinned pele bundle (#195)

* refactor(ci): validate diagrams with pele and fail when missing (#195)

* refactor(epub): render diagrams as flattened pele svg (#195)

* docs: document pele diagram rendering and node 20 setup (#195)

* test(epub): assert numbered labels reach pele unescaped (#195)

* fix(scripts): address review feedback (#195)

* fix(website): keep pele zoom controls off diagram labels (#195)

Pele (zoom: 'auto') draws an opaque zoom box over the top-right corner
of every diagram it shrinks to fit, which hid labels. When that box is
shown, div.mermaid now gets top padding so the diagram starts below it.
Top room rather than side room: Pele lays diagrams out to the content
width, so side padding would shrink them further and re-lay them out.

Zoom also makes each shrunk diagram a tab stop, but the SVG had no
accessible name. Name every SVG Pele draws after the nearest heading
plus its diagram kind ("Architecture - flowchart"). Pele draws a new
<svg> on resize and font load, so the name is set in onRender. SVGs
named by accTitle keep their own name.

* fix(scripts): load the cached pele bundle as ESM on node 20 (#195)

pele_render.mjs imports Pele's ES module build, dist/pele.js, which was
cached as a bare pele.js with no package.json "type": "module" beside
it. Node.js 20.0-20.18 and 22.0-22.6 have no ESM syntax detection, so
they load that file as CommonJS and crash on `export`, failing
check_mermaid.py and build_epub.py on a supported Node.

Cache dist/pele.js as pele.mjs (the same sha256-pinned file) and hand
that path to the helper, so every Node.js >= 20 loads it as an ES
module. A cache holding only pele.js downloads and verifies pele.mjs
once. A test turns off syntax detection to reproduce the old Node
behaviour on newer Node.
2026-10-19 14:17:01 +02:00

1.2 KiB
Raw Permalink Blame History

EPUB 构建脚本

功能

这个脚本会把整份指南构建成 EPUB 电子书,方便离线阅读。

需求

  • Python 环境
  • uv
  • 相关依赖
  • Node.js >= 20(Mermaid 图表由固定版本的 Pele 渲染,首次运行时下载并缓存到 scripts/.vendor-cache/pele/)

快速开始

最简单的方式是直接让 uv 帮你处理依赖:

uv run scripts/build_epub.py

开发环境

如果你要修改脚本本身,可以先创建虚拟环境,再安装开发依赖。

# 创建虚拟环境

# 激活并安装依赖

# 运行测试

# 运行脚本

命令行选项

常见选项包括:

  • 指定输出路径
  • 打开详细日志
  • 限制并发请求

示例

# 带详细输出构建

# 指定输出位置

# 限制并发数(遇到限流时)

输出

脚本会生成 EPUB 文件,里面包含所有内容和渲染后的图表。

运行测试

你可以用虚拟环境或直接通过 uv 运行测试。

依赖

脚本依赖的包会在项目的开发依赖里列出。

故障排查

  • 检查 uv 是否可用
  • 检查 Python 版本
  • 检查依赖是否安装完整
  • 检查 node --version 是否 >= 20;首次构建需要联网下载 Pele 包