PDF of an encrypted site, printed at commit
An encrypted site offers its PDFs (the sections of
docs.pdf, the decks of
publish.pdf) like any other site:
the button above the docs pages, "Download the deck (PDF)" in the toolbar of each deck, and
<PdfDownload> in an MDX page. This page is for a site whose host has no Chromium to print them,
such as Vercel when it builds on git push. The PDFs are printed on your machine at each commit,
kept sealed in the repository, and copied by the host's build.
Why
- Printing needs Chromium.
recit-prints the PDFs with Playwright's Chromium. A host's build image usually lacks it, and installing it there downloads about 110 MB on every build (Deploy on Vercel).site build -- pdf - An encrypted site draws a new key on every build. A PDF sealed by one build does not open in another, so you cannot copy the PDFs of your local build into the host's.
So the PDFs are printed where Chromium is (your machine, in a git hook) into a store, a folder in the repository that is sealed by the site's password. The host's build opens the store with that password, which it already has, and seals each PDF again with its own key. It needs only Node, no browser.
The circuit
- At commit.
recit export --prints the PDFs that read one of the staged files intoto pdf -- site . -- prebuilt -- changed <files> recit-pdf/, sealed. The hook adds the folder to the commit. - On the host.
recit-, withoutsite build --pdf, findsrecit-pdf/, opens it with the password and seals each PDF again with the build's key. It then lists them inexports.jsonand in the envelope of the build (recit-), the same wayaccess.json --pdfdoes. WithVERCELset, this happens before the build moves to.vercel/.output/ static - In the site. The deck toolbar and the docs button find the PDFs in
exports.json,<PdfDownload>links the path it is given, and all three decrypt the file in the page: the download starts with%PDF-.
A site that runs recit- keeps doing so; nothing changes for it.
The store
recit-pdf/ holds one sealed file per PDF, at the path it gets in the build (pdf/,
stories/). It also holds recit-, the manifest, sealed too, and
recit-, the envelope of the store. Change the folder with publish.:
recit.config.ts
- Sealed by the password, never by a key in the repository. The store's envelope is the same kind as the build's: a content key of its own, wrapped by the password (PBKDF2). Reading the repository is not enough to open a PDF. On a site in clear, the store is in clear.
- A fingerprint per PDF. The manifest records, for each PDF, the SHA-256 of what it was printed
from. For a deck, that is its source, the config it is built with, its
customCssand the local files it names. For a docs section, it is the pages of the section, the list of the docs pages, the config and the site's sheet. The Récit version is recorded too. A Markdown link to a page or a deck is not a source: the PDF shows the link, so editing the deck does not reprint the section. - Deterministic. A PDF whose sources did not change is not printed again, and a file whose content did not change keeps its bytes. A commit that touches one deck changes that deck's file and the manifest, nothing else.
Print it once, then commit it:
Bash
The command builds the site first (recit-, which needs @recit/site in the site's
dependencies), then prints. It reads the password from the variable named by access. the
way recit- does: the environment first, then the site's .env files (.env,
.env.local, .env., .env., the last one that sets it wins). A
variable exported in your shell always wins over the files. Keep the password in .env.local, which
git ignores (see below): the hook then finds it without an export. The password is never printed,
and never written in clear into the store or its manifest.
The git hook
With lefthook, at the root of the repository:
lefthook.yml
For a site in a subfolder of the repository (sites/www), run the command there. lefthook then
gives {files} relative to that folder:
lefthook.yml
--changed {files}prints only the PDFs whose fingerprint reads one of the staged files: a commit that touches one deck prints that deck, in seconds. A commit that touches no source prints nothing and starts neither the build nor a browser.files:lists the deleted files too. lefthook's owngit diff -- name- only -- cached {staged_leaves them out, and skips the command when a commit only deletes: the PDF of a deleted deck would then stay in the store.files} git add recit-stages what was printed and what was removed: a deck that is no longer published loses its PDF in the same commit.pdf - The hook needs Chromium (
pnpm exec playwright install chromium, once) and the password, in the environment or in a.envfile of the site such as.env.local. Without them, the commit stops with the reason. LEFTHOOK=or0 git commit git commit --skips the hook. The PDFs are then older than their sources. The build says so, and the CI check below fails.no- verify
Another hook manager works the same way: run the command with the staged files, deleted ones
included, then git add the store.
The options of the PDFs (notes, colorMode, page.size) come from the config, in publish.pdf
and docs.pdf: a change there reprints the PDFs it concerns. --prebuilt refuses --notes,
--color-mode and --page-size, which no fingerprint would record.
.gitignore
The store is committed. The build output and the environment files are not:
.gitignore
Do not ignore recit-pdf/: the host's build reads it from the repository. Do exclude it from your
formatter and linter ("!**/ in Biome's files., ignorePatterns of oxfmt,
.prettierignore): on an encrypted site its files, recit- included, are sealed bytes, not
text, and a tool that rewrites them breaks the store.
Keep the password out of the repository: on Vercel it is an environment variable of the project. The
.env. of Récit's sealed example is a test fixture, not a model.
What the build does
recit- reports the store before the Vite build:
Code
| Case | What happens |
|---|---|
| the store opens, every fingerprint matches | the PDFs are sealed again and listed, with the line above |
| a PDF is older than its sources | a warning names it (below), and the PDF is still copied |
the same, with --strict-pdf | the build fails |
| the source of a deck is gone (no longer published) | a warning names it, and its PDF is left out of the build |
| the password is missing or wrong | the build fails: RECIT_ |
| a store in clear on an encrypted site, or the reverse | the build fails |
| a file or the envelope of the store was edited by hand | the build fails: the file no longer opens or matches the manifest |
recit- | --pdf prints from this build; the store is ignored, with a message |
recit- | the store is left out |
recit- | the store is ignored, with a warning |
A PDF that does not match its sources is a warning by default, not a failure. The host cannot print
it again, and a site with a slightly old PDF is better than a failed deployment. To make it a
failure, use recit-, or run the CI check.
A staleness warning
Code
Each line names the deck or the docs section, its file in the store, and the sources that changed
since it was printed. docs/ in that list means the list of docs pages changed (a page added,
removed or renamed); "the list of the decks of stories/" means a deck was added to or removed from
publish.dir without a new print. The PDF of a deck whose source is gone is not copied at all: the
warning says so. On your machine:
Bash
--changed without a file list compares every fingerprint and prints what differs. A new Récit
version counts as a change for every PDF. To force a reprint of everything, run the command without
--changed.
Check the store in CI
Bash
--check prints nothing and writes nothing. It lists the PDFs that are missing, out of date or no
longer asked for, and exits with code 1 when there is one. It needs the password in the CI's
environment, but not Chromium. Run it in CI (on pushes to main and on pull requests) to catch a
commit made without the hook.
PowerPoint decks in the same store (preview)
With @recit/pptx installed next to recit (Exporting), the published
decks of a site go into the same publish. store (recit-pdf/ by default), sealed by
the same password on an encrypted site:
Bash
- Each deck is exported on its own (no
recit-first); passsite build --pptx-to store one 2× slide picture per slide with speaker notes kept.images - The PDF command leaves the
.pptxentries ofrecit-untouched, andpdf.json --to pptxleaves the PDFs untouched. A site that ships both runs both commands inlefthook.ymlbeforegit add recit-.pdf recit-re-seals thesite build .pptxfiles next to each deck's page, lists them inexports.json(kind: "pptx"), and warns withrecit export --when one is older than its sources (to pptx -- site . -- prebuilt -- changed --strict-pdffails instead).
The manifest, exports.json
How recit- and recit export -- or --to pptx write exports.json is covered in
The circuit and above. Every other command or target that emits manifested files —
recit render (MP4, captions, transcript, stills and posters) and recit export with --to images
(cards, slides, slices, and PNG or SVG charts from *.chart.json or --charts), --to epub,
--to ics, --to rss, --variants, or a plugin --to exporter — merges its entries into the same
manifest next to its output (ExportManifestSchema of @recit/, recit schema exports,
preview), keyed and sorted by files.path, so the deck toolbar, the docs PDF button
(DocsPdfButton), <StoryGallery> of @recit/ and tooling read a single file:
| Key | Subject | Description |
|---|---|---|
$schema | envelope | Optional JSON Schema URL ("https://) |
version | envelope | Manifest format version (1, required) |
files | envelope | Array of exported file entries, sorted by files.path (required) |
files.path | identity | Relative path of the exported file from the manifest's folder (required) |
files.kind | identity | File kind: "pdf", "epub", "ics", "rss", "png", "jpeg", "webp", "svg", "json", "vtt", "txt", "mp4", "plugin" or "pptx" (required) |
files.source | identity | Story path, docs route or config entry the file came from (required) |
files.locale | identity | BCP 47 locale tag of the file (required) |
files.bytes | identity | File size in bytes, integer >= 0 (required) |
files.sha256 | identity | 64-character lowercase hex SHA-256 digest of the file (required) |
files.origin | origin | Discriminated union naming what produced the file (required) |
files. | origin | "story", "block" or "tool" (required) |
files. | origin | Story format id ("deck", "motion", "docs", "report", "webtoon", "book", "roadmap", "calendar", "webstory", "glossary", "directory", "atlas" or "form") when files. is "story" |
files. | origin | Registered block directive name (such as "form" or "chart") when files. is "block" |
files. | origin | Tool id ("skills") when files. is "tool" (reserved in the schema; no command writes it yet) |
files.preset | media and copy | Optional output preset name (such as "instagram-) |
files. | media and copy | Optional variant key from the variants file ({variant}) |
files.aspect | media and copy | Optional aspect ratio string ("4:5", "9:16"…) |
files. | media and copy | Optional publishing channel name (such as "Instagram" or "LinkedIn") |
files.copy | media and copy | Optional post copy resolved for files.locale |
files. | media and copy | Main post text (required when files.copy is present) |
files. | media and copy | Optional array of alternative hook strings |
files. | warnings | Optional array of non-fatal checks recorded on a file that was still written |
files. | warnings | Check code, such as "safe-area" or "overflow" (required on each warning) |
files. | warnings | Human-readable warning message (required on each warning) |
files. | warnings | Optional id of the scene where the warning occurred |
files.pages | documents and feeds | Page count, positive integer (files.) |
files.scope | documents and feeds | Optional PDF scope: "story", "page" or "section" (files.) |
files.routes | documents and feeds | Optional array of site routes starting with "/" covered by the file (files. and "pptx") |
files.title | documents and feeds | Optional label shown on the download button (files. and "pptx") |
files. | documents and feeds | Optional PNG of the first page of a story's PDF, written next to it by recit export -- (files.; none on an encrypted site) |
files. | documents and feeds | Relative path of the PNG from the manifest's folder (<name>.) |
files. | documents and feeds | Width of the PNG in pixels |
files. | documents and feeds | Height of the PNG in pixels |
files. | documents and feeds | Chapter count in the spine, positive integer (files.) |
files.events | documents and feeds | VEVENT count in the file, positive integer (files.) |
files. | documents and feeds | Optional boolean marking a calendar feed apps subscribe to (files.) |
files.items | documents and feeds | <item> count in the feed, positive integer (files.) |
files.width | images and films | Pixel width, positive integer (files., "jpeg", "webp", "svg" and "mp4"; an SVG takes it from its viewBox) |
files.height | images and films | Pixel height, positive integer (files., "jpeg", "webp", "svg" and "mp4"; an SVG takes it from its viewBox) |
files.scene | images and films | id of the scene or ready chart shown in the picture (files., "jpeg", "webp" and "svg") |
files.alt | images and films | Optional alternative text of the picture (files., "jpeg", "webp" and "svg") |
files.slice | images and films | Optional 1-based slice number of a webtoon episode, starting in files.scene (files., "jpeg", "webp" and "svg") |
files.role | images and films | Optional picture role, "poster" for a film cover (files., "jpeg", "webp" and "svg") |
files.fps | images and films | Frame rate in frames per second, positive integer (files.) |
files.frames | images and films | Film length in frames at files.fps, positive integer (files.) |
files.cues | images and films | Cue count in the WebVTT caption file, integer >= 0 (files.) |
files. | blocks, films, tools | "definition" or "json- on files. (reserved in the schema; no command writes it yet), or "transcript" on files. |
files.id | blocks, films, tools | id of the block (such as a :::form) the JSON file comes from (files., reserved in the schema; no command writes it yet) |
files.plugin | blocks, films, tools | Name of the Récit plugin whose exporter wrote the file (files., preview) |
files.target | blocks, films, tools | --to target key from the plugin's exporters (files., preview) |
files. | blocks, films, tools | Optional MIME type reported by the plugin exporter (files., preview) |
files.slides | PowerPoint report | Slide count, positive integer (files., preview) |
files.report | PowerPoint report | Array of per-slide conversion reports, in slide order (files., preview) |
files. | PowerPoint report | 1-based slide number in the deck (required on each item) |
files. | PowerPoint report | Optional id of the scene when the deck sets one |
files. | PowerPoint report | Count of editable PowerPoint elements: text boxes, tables, images and shapes (integer >= 0, required) |
files. | PowerPoint report | Count of elements rasterised as a picture of their rendering (integer >= 0, required) |
files. | PowerPoint report | Whether the slide's speaker notes were written to PowerPoint notes (boolean, required) |
files. | PowerPoint report | Array listing each element rasterised as a picture and why (required) |
files. | PowerPoint report | Selector or tag of the rasterised element, such as pre.mermaid or svg (required on each fallback) |
files. | PowerPoint report | Reason the element was rasterised (required on each fallback) |
Coming from a home-made circuit
A site that printed its PDFs with its own scripts can drop them. That covers a script run at commit
that re-encrypted the PDFs with a project key, the key module, the folder of .bin files, the
script that injected them after the build, a custom download button, and a CSS rule that hid
DocsPdfButton. Instead:
- Delete these scripts, the key module and the
.binfolder. The key was in clear in the repository, so treat it as public. - Replace the custom button with
<PdfDownload>, and the CSS rule withdocs..pdf. button - Print the store once, paste the
lefthook.ymlabove, and build with a plainrecit-.site build