1.16 part 12/18: Almanac: the book as a PDF, Almanac HD and the Golden Record
Part 12 of 18 of Zimi 1.16.0: Almanac: the book as a PDF, Almanac HD and the Golden Record. Base: line/1.16.0-11-almanac-page (part 11); the diff shows only this part's files. The PR carries the not-a-release label and the version stays 1.15.7, so merging it cuts no release. Merge in order (1 to 17, then 18) with a merge commit, not a squash.
What this is
Three things the Almanac needs off the page. The book of tables is typeset as a PDF by the server without a browser. Almanac HD is fetched once, in two sizes, from the release. The Golden Record pictures become WebP with a credit for each. The Almanac ZIM's own source is also updated; the built ZIM lands on top of part 16.
What changes
zimi/almanacbook.py(new): lays out the book's HTML with PyMuPDF's HTML engine (Story) in Charis SIL, then draws running heads and feet, contents page numbers with dotted leaders, links, the outline, and small vector pictures.render(html, paper)returns the PDF bytes.zimi/almanacmath.py(new): lays out Presentation MathML (Temml's output) in Noto Sans Math and draws it onto a PDF page as embedded text, with TeX-style script sizes, fractions on the maths axis and fences stretched to their content. It refuses DOCTYPEs and entities.zimi/almanacpdf.py: the browser-driven PDF path is replaced. A render runs as its own process (python -m zimi.almanacbook) under a time limit, one at a time with a short queue behind it (past that the server answers busy), and the same document asked again returns the PDF already made. A frozen desktop build renders on the request's thread.zimi/almanachd.py: Almanac HD is one ZIM,zimi_almanac_maxi_<month>, in two sizes, one installed at a time: HD (one release file) and Maximum (zimsplit chunks fetched into a hidden staging folder, each checked against its sha256, the whole book checked before it replaces HD). Reading the release manifest is part of the Ask first, Automatically or Never setting;ZIMI_OFFLINEis Never. Older copies are listed, not deleted.scripts/build_almanac_hd.py,scripts/build_almanac_maxi.py: tiles are cut at each source's native resolution (nothing magnified), with Cassini moon and Phobos tone tables, hole filling and shaded terrain maps added, and the two flavours are built from a pinned tile source.scripts/publish_almanac_tiles.py(new) packs, splits, checks and pins that source; it uploads only with--upload.zimi/assets/almanac-tiles.jsongainshd_sizeandmax_size;.github/workflows/almanac-hd.ymlnotes the memory the build needs and addstifffile.scripts/verify_almanac_qids.py: audits each curated Q-ID against English Wikipedia (wrong item, disambiguation page, missing page);--landmarksauditszimi/static/earth/landmarks-v1.jsonagainst Wikidata and checks every link keyalmanac-earth.jsasks for, exiting 1 so it can gate a release.zimi/static/golden-record/*.webpreplace the.giffiles;credits.jsonnames each picture's owner and whether it is public domain.zimi/builtin/almanac/index.html,local.js,zimi.txt: the ZIM's page loads its scripts in order with a retry for a busy server (kiwix-serve), serves the all-satellites snapshot, drops the old credit line, and the title becomes "Zimi Almanac".
How to review
- Read first:
almanacpdf.py(the subprocess, time limit and queue: a hang or leak holds the server), thenalmanachd.py(consent before any network read, the sha256 checks, what is removed when a size replaces the other). - Then
almanacmath.pylayout(the parser handles client-sent text) andalmanacbook.pyrender(fetches nothing; images come only from the book's own archive). - Risk: data loss in
almanachd.py(HD and Maximum swap, older copies never deleted unasked), network calls (manifest and chunk fetches), and a PDF render's memory and time on a long book. - Skip: the 47 renamed
golden-record/*.webp(binary),tests/test_almanac_hd_sizes.pybeyond its docstring. - Rides here:
tests/test_older_copies_delete.pyfirst passes at this tip (Storage's "Older copies" Delete is the HD change). The ZIM'sindex.htmlloads scripts that land in parts 13 to 16.
Tests
- PDF:
tests/test_almanac_pdf.py(the/almanac/pdfroute: size limit, nothing fetched, one render at a time in its own process killed at its time, the file removed after its time, 501 where PyMuPDF is missing). - HD:
tests/test_almanac_hd.py,tests/test_almanac_hd_sizes.py,tests/test_older_copies_delete.py,tests/test_almanac_zim_size.py. - Browser:
tests/test_almanac_hd_browser.py,tests/test_almanac_hd_climb_browser.py,tests/test_almanac_hd_holes_browser.py. - Own ZIMs in a real kiwix-serve:
tests/test_own_zims_kiwix_serve.py(skips withoutkiwix-serveunless CI requires it). - Q-IDs:
tests/test_almanac_qids.cjs. Tests named for this part that first pass in parts 16 and 17: the HD build, release and workflow tests, the ZIM and Golden Record tests.
Summary by cubic
Typesets the Almanac's book as a PDF without a browser, makes Almanac HD one ZIM in two sizes installed one at a time, and serves the Golden Record pictures as WebP with credits for each.
- Replaces the headless-Chromium path with PyMuPDF's Story engine, which typesets the page's own HTML in Charis SIL.
zimi/almanacbook.pydraws the running heads and feet, contents page numbers with dotted leaders, links, the outline, and vector pictures;zimi/almanacmath.pytypesets Presentation MathML in Noto Sans Math as embedded, subsetted text.- Renders run in their own process under a time limit, one at a time with a short queue (past that the server answers busy); a frozen desktop build renders on the requesting thread.
- Nothing the client sends is fetched (images come only from the book's own archive), and the route answers 501 where PyMuPDF is missing; the MathML parser rejects DOCTYPEs and entities.
Almanac HD
- Almanac HD is one ZIM in two sizes: HD (
zimi_almanac_maxi_<month>, one release file, some layers cut short to fit it) and Maximum (zimi_almanac_ultra_<month>, zimsplit chunks fetched into a hidden staging folder), each chunk checked against its sha256 with the whole book verified before it replaces the other. - Reading the release manifest stays behind the Ask / Automatically / Never setting; older copies are listed, never deleted unasked.
- Tiles are cut at each source's native resolution (nothing magnified) for every world in the 3D view, with Cassini moon and Phobos tone tables, hole filling, and shaded terrain maps;
scripts/publish_almanac_tiles.pypacks, chunks and pins that source, and the two builds draw from it and a hand-built craft folder. - The tile build needs a big machine and no longer finishes on a standard GitHub runner;
scripts/verify_almanac_qids.pyaudits the curated Q-IDs against English Wikipedia and the 3D view's landmarks against Wikidata, exiting 1 so it can gate a release. - The built ZIM's title is now "Zimi Almanac", its page loads scripts in order with a retry for a busy
kiwix-serve, serves the all-satellites snapshot, and a test holds the ZIM to its size budget by storing data files as a compressible type.