"""Generate lib/tt-default-book.json from apps/ebook/content (7-chapter 数字游民).""" from __future__ import annotations import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] META = json.loads((ROOT / "apps/ebook/content/book.json").read_text(encoding="utf-8")) OUT = ROOT / "lib" / "tt-default-book.json" def main() -> None: chapters = [] for ch in META["chapters"]: slug = ch["slug"] md = (ROOT / "apps/ebook/content/chapters" / f"{slug}.md").read_text(encoding="utf-8") chapters.append( { "id": slug, "title": ch["title"], "emoji": ch.get("emoji") or "📖", "content": md, "hook": ch.get("hook") or "", "shareQuote": ch.get("shareQuote") or "", } ) book = { "title": META["title"], "subtitle": META.get("subtitle") or "", "author": META.get("author") or "", "description": META.get("description") or "", "tagline": META.get("tagline") or "", "coverEmoji": "📗", "chapters": chapters, } OUT.write_text(json.dumps(book, ensure_ascii=False, indent=2), encoding="utf-8") print(f"wrote {OUT} chapters={len(chapters)} bytes={OUT.stat().st_size}") if __name__ == "__main__": main()