* 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.
4.9 KiB
Скрипт збірки EPUB
Збірка EPUB-книги з markdown-файлів Claude How-To.
Функції
- Організує розділи за структурою каталогів (01-slash-commands, 02-memory тощо)
- Рендерить Mermaid-діаграми як SVG-зображення через Pele — закріплений бандл, який запускає Node.js; CSS-змінні замінюються звичайними кольорами на білому тлі, тож діаграми видно в будь-якій EPUB-читалці
- Кешує однакові діаграми — кожна унікальна діаграма рендериться лише раз
- Генерує обкладинку з логотипу проєкту
- Конвертує внутрішні markdown-посилання у посилання на розділи EPUB
- Суворий режим помилок — падає, якщо діаграма не може бути відрендерена
Вимоги
- Python 3.10+
- uv
- Node.js >= 20 у
PATHдля рендерингу Mermaid-діаграм. Закріплений бандл Pele завантажується під час першого запуску (мережа потрібна лише раз), перевіряється за sha256 і кешується вscripts/.vendor-cache/pele/
Швидкий старт
# Simplest way - uv handles everything
uv run scripts/build_epub.py
Налаштування розробки
# Create virtual environment
uv venv
# Activate and install dependencies
source .venv/bin/activate
uv pip install -r requirements-dev.txt
# Run tests
pytest scripts/tests/ -v
# Run the script
python scripts/build_epub.py
Параметри командного рядка
usage: build_epub.py [-h] [--root ROOT] [--output OUTPUT] [--verbose]
[--lang {en,vi,zh,ja}]
options:
-h, --help show this help message and exit
--root, -r ROOT Root directory (default: repo root)
--output, -o OUTPUT Output path (default: claude-howto-guide.epub)
--verbose, -v Enable verbose logging
--lang {en,vi,zh,ja} Language to build (default: en)
Приклади
# Build with verbose output
uv run scripts/build_epub.py --verbose
# Custom output location
uv run scripts/build_epub.py --output ~/Desktop/claude-guide.epub
# Build a translated edition
uv run scripts/build_epub.py --lang vi
Вивід
Створює claude-howto-guide.epub у кореневому каталозі репозиторію.
EPUB включає:
- Обкладинку з логотипом проєкту
- Зміст з вкладеними секціями
- Весь markdown-контент, конвертований у EPUB-сумісний HTML
- Mermaid-діаграми, відрендерені як SVG-зображення
Запуск тестів
# With virtual environment
source .venv/bin/activate
pytest scripts/tests/ -v
# Or with uv directly
uv run --with pytest --with pytest-asyncio \
--with ebooklib --with markdown --with beautifulsoup4 \
--with pillow \
pytest scripts/tests/ -v
Залежності
Керуються через PEP 723 inline script metadata:
| Пакет | Призначення |
|---|---|
ebooklib |
Генерація EPUB |
markdown |
Конвертація Markdown → HTML |
beautifulsoup4 |
Парсинг HTML |
pillow |
Генерація обкладинки |
Усунення проблем
Збірка падає з Pele is unavailable: Встановіть Node.js >= 20 і переконайтеся, що node є у PATH (node --version).
Помилка завантаження або контрольної суми бандла Pele: Перша збірка завантажує закріплений бандл Pele з cdn.jsdelivr.net і перевіряє sha256 кожного файлу. Офлайн або за проксі виконайте одну збірку з доступом до мережі; наступні збірки використовують кеш у scripts/.vendor-cache/pele/<version>/. Невідповідність контрольної суми означає, що завантаження змінене або обірване: видаліть цю папку й зберіть знову.
Відсутній логотип: Скрипт генерує текстову обкладинку, якщо claude-howto-logo.png не знайдено.