Skip to content

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-site build --pdf 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).
  • 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

  1. At commit. recit export --to pdf --site . --prebuilt --changed <files> prints the PDFs that read one of the staged files into recit-pdf/, sealed. The hook adds the folder to the commit.
  2. On the host. recit-site build, without --pdf, finds recit-pdf/, opens it with the password and seals each PDF again with the build's key. It then lists them in exports.json and in the envelope of the build (recit-access.json), the same way --pdf does. With VERCEL set, this happens before the build moves to .vercel/output/static.
  3. 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-site build --pdf 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/lorem.pdf, stories/lorem-deck.pdf). It also holds recit-pdf.json, the manifest, sealed too, and recit-access.json, the envelope of the store. Change the folder with publish.pdf.prebuilt:

TypeScriptrecit.config.ts
export default defineConfig({ docs: { pdf: { sections: ["Lorem"] } }, publish: { pdf: { prebuilt: "recit-pdf" } }, // the default access: { password: { env: "RECIT_SITE_PASSWORD" }, mode: "encrypted" }, });
  • 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 customCss and 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:

TerminalBash
RECIT_SITE_PASSWORD=… pnpm exec recit export --to pdf --site . --prebuilt git add recit-pdf

The command builds the site first (recit-site build, which needs @recit/site in the site's dependencies), then prints. It reads the password from the variable named by access.password the way recit-site build does: the environment first, then the site's .env files (.env, .env.local, .env.production, .env.production.local, 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:

YAMLlefthook.yml
pre-commit: commands: recit-pdf: # The staged files, deleted ones included: {staged_files} leaves deletions out files: git diff --name-only --cached # Prints only the PDFs that read one of these files, then adds the store to the commit run: pnpm exec recit export --to pdf --site . --prebuilt --changed {files} && git add recit-pdf

For a site in a subfolder of the repository (sites/www), run the command there. lefthook then gives {files} relative to that folder:

YAMLlefthook.yml
pre-commit: commands: recit-pdf: root: "sites/www/" files: git diff --name-only --cached run: pnpm exec recit export --to pdf --site . --prebuilt --changed {files} && git add recit-pdf
  • --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: git diff --name-only --cached lists the deleted files too. lefthook's own {staged_files} leaves them out, and skips the command when a commit only deletes: the PDF of a deleted deck would then stay in the store.
  • git add recit-pdf stages what was printed and what was removed: a deck that is no longer published loses its PDF in the same commit.
  • The hook needs Chromium (pnpm exec playwright install chromium, once) and the password, in the environment or in a .env file of the site such as .env.local. Without them, the commit stops with the reason.
  • LEFTHOOK=0 git commit or git commit --no-verify skips the hook. The PDFs are then older than their sources. The build says so, and the CI check below fails.

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
dist .vercel .env*.local

Do not ignore recit-pdf/: the host's build reads it from the repository. Do exclude it from your formatter and linter ("!**/recit-pdf" in Biome's files.includes, ignorePatterns of oxfmt, .prettierignore): on an encrypted site its files, recit-pdf.json 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.production of Récit's sealed example is a test fixture, not a model.

What the build does

recit-site build reports the store before the Vite build:

Code
PDF store recit-pdf/: 3 PDF(s), sealed again with the key of this build.
CaseWhat happens
the store opens, every fingerprint matchesthe PDFs are sealed again and listed, with the line above
a PDF is older than its sourcesa warning names it (below), and the PDF is still copied
the same, with --strict-pdfthe 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 wrongthe build fails: RECIT_SITE_PASSWORD does not open the PDF store …
a store in clear on an encrypted site, or the reversethe build fails
a file or the envelope of the store was edited by handthe build fails: the file no longer opens or matches the manifest
recit-site build --pdf--pdf prints from this build; the store is ignored, with a message
recit-site build --no-pdf-storethe store is left out
recit-site build --experimental-ssrthe 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-site build --strict-pdf, or run the CI check.

A staleness warning

Code
⚠ Stale PDF: deck "lorem-deck" (recit-pdf/stories/lorem-deck.pdf): recit.config.ts changed since it was printed. Print them again on a machine with Chromium: recit export --to pdf --site . --prebuilt --changed, then commit recit-pdf/.

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:

TerminalBash
RECIT_SITE_PASSWORD=… pnpm exec recit export --to pdf --site . --prebuilt --changed git add recit-pdf && git commit -m "Print the PDFs again"

--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

TerminalBash
pnpm exec recit export --to pdf --site . --prebuilt --check

--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.pdf.prebuilt store (recit-pdf/ by default), sealed by the same password on an encrypted site:

TerminalBash
RECIT_SITE_PASSWORD=… pnpm exec recit export --to pptx --site . --prebuilt RECIT_SITE_PASSWORD=… pnpm exec recit export --to pptx --site . --prebuilt --changed RECIT_SITE_PASSWORD=… pnpm exec recit export --to pptx --site . --prebuilt --check
  • Each deck is exported on its own (no recit-site build first); pass --pptx-images to store one 2× slide picture per slide with speaker notes kept.
  • The PDF command leaves the .pptx entries of recit-pdf.json untouched, and --to pptx leaves the PDFs untouched. A site that ships both runs both commands in lefthook.yml before git add recit-pdf.
  • recit-site build re-seals the .pptx files next to each deck's page, lists them in exports.json (kind: "pptx"), and warns with recit export --to pptx --site . --prebuilt --changed when one is older than its sources (--strict-pdf fails instead).

The manifest, exports.json

How recit-site build and recit export --to pdf 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/core/schema, recit schema exports, preview), keyed and sorted by files.path, so the deck toolbar, the docs PDF button (DocsPdfButton), <StoryGallery> of @recit/site-stories and tooling read a single file:

KeySubjectDescription
$schemaenvelopeOptional JSON Schema URL ("https://recit.dev/schema/v1/exports.json")
versionenvelopeManifest format version (1, required)
filesenvelopeArray of exported file entries, sorted by files.path (required)
files.pathidentityRelative path of the exported file from the manifest's folder (required)
files.kindidentityFile kind: "pdf", "epub", "ics", "rss", "png", "jpeg", "webp", "svg", "json", "vtt", "txt", "mp4", "plugin" or "pptx" (required)
files.sourceidentityStory path, docs route or config entry the file came from (required)
files.localeidentityBCP 47 locale tag of the file (required)
files.bytesidentityFile size in bytes, integer >= 0 (required)
files.sha256identity64-character lowercase hex SHA-256 digest of the file (required)
files.originoriginDiscriminated union naming what produced the file (required)
files.origin.typeorigin"story", "block" or "tool" (required)
files.origin.formatoriginStory format id ("deck", "motion", "docs", "report", "webtoon", "book", "roadmap", "calendar", "webstory", "glossary", "directory", "atlas" or "form") when files.origin.type is "story"
files.origin.blockoriginRegistered block directive name (such as "form" or "chart") when files.origin.type is "block"
files.origin.tooloriginTool id ("skills") when files.origin.type is "tool" (reserved in the schema; no command writes it yet)
files.presetmedia and copyOptional output preset name (such as "instagram-post")
files.variantmedia and copyOptional variant key from the variants file ({variant})
files.aspectmedia and copyOptional aspect ratio string ("4:5", "9:16"…)
files.channelmedia and copyOptional publishing channel name (such as "Instagram" or "LinkedIn")
files.copymedia and copyOptional post copy resolved for files.locale
files.copy.textmedia and copyMain post text (required when files.copy is present)
files.copy.alternatesmedia and copyOptional array of alternative hook strings
files.warningswarningsOptional array of non-fatal checks recorded on a file that was still written
files.warnings.codewarningsCheck code, such as "safe-area" or "overflow" (required on each warning)
files.warnings.messagewarningsHuman-readable warning message (required on each warning)
files.warnings.scenewarningsOptional id of the scene where the warning occurred
files.pagesdocuments and feedsPage count, positive integer (files.kind: "pdf")
files.scopedocuments and feedsOptional PDF scope: "story", "page" or "section" (files.kind: "pdf")
files.routesdocuments and feedsOptional array of site routes starting with "/" covered by the file (files.kind: "pdf" and "pptx")
files.titledocuments and feedsOptional label shown on the download button (files.kind: "pdf" and "pptx")
files.previewdocuments and feedsOptional PNG of the first page of a story's PDF, written next to it by recit export --to pdf (files.kind: "pdf"; none on an encrypted site)
files.preview.pathdocuments and feedsRelative path of the PNG from the manifest's folder (<name>.preview.png)
files.preview.widthdocuments and feedsWidth of the PNG in pixels
files.preview.heightdocuments and feedsHeight of the PNG in pixels
files.chaptersdocuments and feedsChapter count in the spine, positive integer (files.kind: "epub")
files.eventsdocuments and feedsVEVENT count in the file, positive integer (files.kind: "ics")
files.subscribabledocuments and feedsOptional boolean marking a calendar feed apps subscribe to (files.kind: "ics")
files.itemsdocuments and feeds<item> count in the feed, positive integer (files.kind: "rss")
files.widthimages and filmsPixel width, positive integer (files.kind: "png", "jpeg", "webp", "svg" and "mp4"; an SVG takes it from its viewBox)
files.heightimages and filmsPixel height, positive integer (files.kind: "png", "jpeg", "webp", "svg" and "mp4"; an SVG takes it from its viewBox)
files.sceneimages and filmsid of the scene or ready chart shown in the picture (files.kind: "png", "jpeg", "webp" and "svg")
files.altimages and filmsOptional alternative text of the picture (files.kind: "png", "jpeg", "webp" and "svg")
files.sliceimages and filmsOptional 1-based slice number of a webtoon episode, starting in files.scene (files.kind: "png", "jpeg", "webp" and "svg")
files.roleimages and filmsOptional picture role, "poster" for a film cover (files.kind: "png", "jpeg", "webp" and "svg")
files.fpsimages and filmsFrame rate in frames per second, positive integer (files.kind: "mp4")
files.framesimages and filmsFilm length in frames at files.fps, positive integer (files.kind: "mp4")
files.cuesimages and filmsCue count in the WebVTT caption file, integer >= 0 (files.kind: "vtt")
files.contentblocks, films, tools"definition" or "json-schema" on files.kind: "json" (reserved in the schema; no command writes it yet), or "transcript" on files.kind: "txt"
files.idblocks, films, toolsid of the block (such as a :::form) the JSON file comes from (files.kind: "json", reserved in the schema; no command writes it yet)
files.pluginblocks, films, toolsName of the Récit plugin whose exporter wrote the file (files.kind: "plugin", preview)
files.targetblocks, films, tools--to target key from the plugin's exporters (files.kind: "plugin", preview)
files.mediaTypeblocks, films, toolsOptional MIME type reported by the plugin exporter (files.kind: "plugin", preview)
files.slidesPowerPoint reportSlide count, positive integer (files.kind: "pptx", preview)
files.reportPowerPoint reportArray of per-slide conversion reports, in slide order (files.kind: "pptx", preview)
files.report.slidePowerPoint report1-based slide number in the deck (required on each item)
files.report.idPowerPoint reportOptional id of the scene when the deck sets one
files.report.nativePowerPoint reportCount of editable PowerPoint elements: text boxes, tables, images and shapes (integer >= 0, required)
files.report.imagesPowerPoint reportCount of elements rasterised as a picture of their rendering (integer >= 0, required)
files.report.notesPowerPoint reportWhether the slide's speaker notes were written to PowerPoint notes (boolean, required)
files.report.fallbacksPowerPoint reportArray listing each element rasterised as a picture and why (required)
files.report.fallbacks.elementPowerPoint reportSelector or tag of the rasterised element, such as pre.mermaid or svg (required on each fallback)
files.report.fallbacks.reasonPowerPoint reportReason 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:

  1. Delete these scripts, the key module and the .bin folder. The key was in clear in the repository, so treat it as public.
  2. Replace the custom button with <PdfDownload>, and the CSS rule with docs.pdf.button.
  3. Print the store once, paste the lefthook.yml above, and build with a plain recit-site build.