Skip to content

Recipes, part 6: the cookbook as PDF and EPUB - #98

Merged
pietrangelo merged 1 commit into
mainfrom
claude/project-thread-m3jzg5
Nov 1, 2026
Merged

pietrangelo merged 1 commit into
mainfrom
claude/project-thread-m3jzg5

Conversation

@pietrangelo

Copy link
Copy Markdown
Owner

This is the last part of the recipes plan: exporting a cookbook as a book.

What changes

  • Entry point: when a category in the library holds recipes, either directly or in its subcategories, the app bar shows «Esporta il ricettario». It first asks for the passphrase. The sheet then warns that the file is not encrypted and offers PDF (golden 144 × 233 mm, A5 or A4) or EPUB, with or without photos. The book is made on the device and never goes through the server.
  • Content (lib/cookbook/cookbook.dart, cookbook_pages.dart):
    • There is one chapter per category, in library order, with each chapter's recipes sorted by title. The ingredient index merges names that differ only in case, accents or spacing. A book holds at most 2584 recipes.
    • Each recipe goes through PublicationPolicy and PageComposer, so the book shows exactly what serv.pub would show: no private note links and no vault ids.
  • Colours: CategoryColours in publishing is a Dart port of colour.rs. A test checks it against the server's values.
  • PDF (cookbook_pdf.dart, pdf package):
    • Fonts are static Inter 400/600 and Plus Jakarta Sans 700, instanced from the app's variable fonts (OFL), and only the glyphs used are written into the file.
    • Layout uses a φ type scale and φ margins: a cover with the first photo in a golden rectangle, linked contents, chapter openers in each chapter's tint, and each recipe starting on a new page. A recipe page has its golden photo, a facts box, ingredients at 38.2 % and steps at 61.8 %, and step photos.
    • A step video becomes a QR code to its published page, or a line saying it is in the note when the recipe is not published.
    • The ingredient index has clickable page numbers. The document is laid out twice so those page numbers are known.
  • EPUB 3 (cookbook_epub.dart): the mimetype entry comes first and is stored uncompressed. The book has package.opf, nav.xhtml, a page per chapter and per recipe, and a linked ingredient index. The CSS uses the φ scale and the chapter colours; there is no script and no font. All text is escaped, Markdown is read by the app's own reader, and only http(s) links are kept.
  • Photos: each photo is decoded by the platform, scaled to 987 or 610 px, and re-encoded as JPEG from its pixels only, so no EXIF survives. The original bytes are zeroed afterwards.
  • Saving on phones: a new NativeFileExchange (file_picker) uses the Storage Access Framework on Android and the document picker on iOS. It is now passed to VaultGate.files on mobile too, so «Backup ed esportazione» also appears on Android and iOS.
  • Refactor: describeField is moved out of the publish sheet so the book can reuse it.

Tests

  • test/cookbook/cookbook_test.dart:
    • chapters, order and ingredient index;
    • the page matches serv.pub's;
    • the published address is used for the QR code;
    • the recipe limit;
    • PDF in all three sizes;
    • EPUB structure.
  • Adversary tests:
    • hostile titles and Markdown (<script>, javascript:, trackers) never become markup;
    • EXIF is gone from photos.
  • test/cookbook/cookbook_sheet_test.dart: the warning, PDF, EPUB without photos, and a category with no recipes.
  • packages/publishing/test/category_colours_test.dart.
  • The full app suite passes (813 tests, flutter analyze clean), as do publishing and architecture_guard.
  • I checked the rendered PDF pages visually with pdftoppm. Every EPUB XML file parses as well-formed. I did not run epubcheck in this environment.

Known limits

  • The exported file is in clear: the sheet says so before export.
  • A book with very many photos uses a lot of memory on a phone. Exporting without photos avoids this.

Generated by Claude Code

A category that holds recipes can be exported as a book, made on the
device after the passphrase and a warning that the file is in clear:
a PDF laid out in phi (golden 144 x 233 mm, A5 or A4) with a cover,
linked contents, a chapter per category in its serv.pub colour, each
recipe from a new page, a QR code to a published step video and an
index of ingredients; or an EPUB 3 for e-readers. Recipes go through
the same PublicationPolicy and PageComposer as serv.pub, so no private
link or vault id reaches the file; pictures are rewritten as JPEG from
their pixels alone. The book's category colours are a Dart port of the
server's colour.rs. Files are saved on Android and iOS through the
system document dialogs, which also brings backup and export to phones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rvr6HJwgZKVC2FvU1Tmgyp
@pietrangelo
pietrangelo marked this pull request as ready for review November 1, 2026 12:51
@pietrangelo
pietrangelo merged commit 574e87a into main Nov 1, 2026
11 checks passed
@pietrangelo
pietrangelo deleted the claude/project-thread-m3jzg5 branch November 1, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants