Skip to content

feat(docs): per-page share cards (#286) - #381

Merged
baldurpan merged 9 commits into
mainfrom
286-share-cards
Nov 29, 2026
Merged

baldurpan merged 9 commits into
mainfrom
286-share-cards

Conversation

@baldurpan

Copy link
Copy Markdown
Contributor

Every docs page now has its own share card, drawn in the build, with a versioned URL and a card text that survives a square crop. Plan and ledger: #286.

What landed

  1. Card art script and the committed art, docs/scripts/build-og-art.mjs and docs/src/assets/og-art.png (1652c06).
  2. Card renderer and card set (463e6d0).
  3. Build-time /og/ route, one PNG per page plus site.png (ad1fc68).
  4. Per-page share tags and the ?v= hash integration (d4476da).
  5. Audit rules for the new tags; docs/public/og-image.jpg removed (0cc4c62).
  6. Documentation (2ed3960).

Waiting

Closes #286

Phase 1 of share-cards. docs/scripts/build-og-art.mjs draws the hero's
branch graph (buildTargets, seeded mulberry32) in the hero's greens behind
a bevelled panel with CanvasKit, and writes docs/src/assets/og-art.png as a
1200x630 palette PNG with sharp. Run by hand, never by the build (D1).

- canvaskit-wasm 0.42.0 and sharp 0.35.5 as docs devDependencies, exact-pinned
  (build tools, per tooling/dependencies.md). sharp loads and writes a palette
  PNG under allowBuilds: false through its prebuilt binary.
- Michroma TTF and its OFL vendored in docs/src/assets/og-fonts/ (D8).
- targets.ts imports ./geometry.ts so Node's type stripping resolves it.
- Art: 24,604 bytes; contrast ice 13.46:1, ice-dim 7.61:1; graph x 447-753,
  panel x 313-887, inside the safe square 285-915 less 28.

Gate 1: check, typecheck, docs typecheck, build, docs:build,
worker:bundle-check, docs:audit-dist, test (4147), docs:test (1814) and the
test-markers grep all exit 0. Gate 2: reviewer subagent, FAIL then PASS WITH
NOTES after one loopback (graph flipped, cyan instead of the hero's greens,
test margin taken from the script).
Phase 2 of share-cards. renderCard draws Michroma text, centred, over the
committed og-art.png with CanvasKit and returns a 1200x630 palette PNG via
sharp (D2). A page title takes the largest size from 40px to 14px that fits
two lines and throws, naming the title, when it needs three; nothing is
shortened. ogCards gives site plus one card per page keyed by the
collection id (the landing uses the site card, D3); ogImageAlt describes the
card and never repeats the title alone (D6).

- 29 cards; largest 29,360 bytes; smallest real title size 21px.
- Text stays inside the art's measured TEXT_BOX (x 341-859, y 203-427); a test
  measures >= 4.5:1 behind every real text box.

Gate 1: check, typecheck, docs typecheck, build, docs:build,
worker:bundle-check, docs:audit-dist, test (4147), docs:test (1829) and the
test-markers grep all exit 0. Gate 2: reviewer subagent, PASS WITH NOTES.
Test fixtures then made to drop a trailing /index from ids as Astro does
(the reviewer's note 1); check, docs typecheck and docs:test re-run green.
Phase 3 of share-cards. docs/src/pages/og/[...route].ts is a static
endpoint with one getStaticPaths entry per ogCards key, each a PNG response
drawn by renderCard (D2, D3): og/site.png plus og/<collection id>.png per
page, e.g. og/commands/branch.png and og/commands.png.

- docs:build writes 29 PNGs to dist/og, each 1200x630 palette, 26,923 to
  29,360 bytes; none in the sitemap or llms.txt. CanvasKit's WASM and the art
  load from the bundled chunk unchanged, so no locateFile was needed.

Gate 1: check, typecheck, docs typecheck, build, docs:build,
worker:bundle-check, docs:audit-dist, test (4147), docs:test (1829) and the
test-markers grep all exit 0. Gate 2: reviewer subagent, PASS WITH NOTES.
Phase 4 of share-cards. Head.astro drops Starlight's and the config's image
and locale entries and writes each page's own og:image, og:image:type
(image/png), :width, :height, :alt, twitter:image, twitter:image:alt and
og:locale en_US (D6); the landing, the 404 and /dox/ name og/site.png.
astro.config.mjs no longer writes the site-wide JPEG tags.

og-image-version.ts is an integration listed before starlight() whose
astro:build:done hook appends ?v=<first 12 hex of the PNG's SHA-256> to
og:image and twitter:image, and fails the build on a URL that is not a PNG
under /worktree/og/, one that already has a query, or a PNG not in the build
(D5).

Deviation from the plan's file list: audit-dist.mjs's builtFileOf now drops a
URL's query and fragment before resolving the file, as a static server does;
without it the ?v= query failed all 29 pages' "is a file in the build" rule.
Phase 5 still owns the share-image rule rewrite.

Gate 1: check, typecheck, docs typecheck, build, docs:build,
worker:bundle-check, docs:audit-dist, test (4147), docs:test (1836) and the
test-markers grep all exit 0. Loopbacks: Gate 1 once (the audit query),
Gate 2 once (an `as Error` assertion; a wrong plan citation in Head.astro).
Gate 2: reviewer subagent, PASS.
Phase 5 of share-cards. audit-dist.mjs replaces its JPEG/1200x630 share
rules with auditShare, run on the 29 pages, the 404 and /dox/ (D9), one
failure line per rule: og:image is https://northguild.dev/worktree/og/<key>.png
?v=<12 hex> and the hash is the file's SHA-256; the file is a PNG by its
header, 1200x630, at most 307,200 bytes; og:image:type image/png and the
width and height tags say so; twitter:image equals og:image; exactly one
og:locale, en_US; both alts present and neither is the page's title (D6);
the card is the page's own except on the landing, the 404 and /dox/, which
name site.png. Each rule has a test whose fixture breaks only that rule.

docs/public/og-image.jpg is deleted (D7). og-image-version.test.ts's
non-card example URL moves off og-image.jpg so nothing names the old file.

Gate 1: check, typecheck, docs typecheck, build, docs:build,
worker:bundle-check, docs:audit-dist, test (4147), docs:test (1860) and the
test-markers grep all exit 0; mutation spot checks on the hash and locale
rules turn their tests red. Gate 2: reviewer subagent, FAIL then PASS after
one loopback (the missing-tag test now asserts the exact failure list).
…286)

Phase 6 of share-cards. context/verify.md's Audit section describes the PNG
card per page with ?v=, the hash, the 307,200-byte limit, og:locale en_US and
the alt rules, on the pages, the 404 and /dox/; "Not run by Gate 1" names
build-og-art.mjs as generation. context/stack.md names the art script, the
renderer, the /og/ route, the integration and the committed art and fonts.
docs/README.md gains a "Share cards" section: the build makes the cards, and
how and when to redraw the art and commit it.

Gate 1 (docs-only): pnpm check exits 0, diff read. Gate 2: reviewer
subagent, FAIL then PASS after one loopback (the site card's text, the
script missing from verify.md, two README claims about the script).

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-reviewer: minor issues

Each docs page now gets its own share card, made during the build: committed art, text drawn with CanvasKit, PNGs written by an /og/ route, per-page tags from Head.astro, a ?v= hash added after the build, and audit rules for all of it. The pieces fit together, and I found no blocking bugs. Two things are worth a look. The test that compares the committed og-art.png byte for byte will probably fail when CI runs on a different OS or CPU than the machine that drew the file. And the renderer keeps its own copy of the text box's position instead of using the art script's. I couldn't see pnpm-lock.yaml, geometry.ts, theme-contrast.mjs or the CI workflows.


Reviewed 5710325 for baldurpan · claude-opus-5-5 via Claude Code · 23 files · left out: pnpm-lock.yaml (lockfile or generated)

Comment thread docs/scripts/build-og-art.test.mjs Resolved
Comment thread docs/src/lib/og-art.ts Resolved
…286)

sharp's zlib-ng deflates the same palette PNG differently by CPU: the art
drawn on darwin-arm64 is 24,604 bytes and on CI's linux-x64 24,603, so the
byte comparison failed on CI with the right picture committed. Decoding both
and comparing the pixels is the check the test meant; reproduced on
linux/amd64 in Docker, where it now passes.

Also derives GRAPH_SCALE from GRAPH_HEIGHT, which was declared and unused.
…OX (#286)

og-art.ts lays card text out in BOX, a hand copy of TEXT_BOX from
build-og-art.mjs, the only region whose 4.5:1 contrast the art script
measures. Export BOX and assert it equals TEXT_BOX, so moving the panel
without the renderer following fails pnpm docs:test.

Raised by baldurs-reviewer on #381.

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-reviewer follow-up: looks good

I have no new findings, and both earlier comments are fixed. The test of the committed art now decodes the committed file and the freshly drawn art with sharp and compares the raw pixels exactly. CI's Linux and your Mac encode the same picture one byte apart. BOX in og-art.ts is now exported, and a new test asserts it equals TEXT_BOX from the art script. verify.md, docs/README.md and the script header now say the check compares pixels, not bytes, and GRAPH_SCALE is now worked out from GRAPH_HEIGHT rather than repeating the sum. The pull request looks ready to merge.

Earlier comments


Reviewed 5f5b859 (changes since 5710325) for baldurpan · claude-opus-5-5 via Claude Code · 5 files

@baldurpan
baldurpan merged commit c585443 into main Nov 29, 2026
1 check passed
@baldurpan
baldurpan deleted the 286-share-cards branch November 29, 2026 20:21
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.

share-cards

1 participant