Repository navigation
Description
share-cards Plan
Written 2026-11-27. Give the docs site a share card that survives a square crop, a versioned URL per card, and a card per page. This issue (#286) is the feature's own record: Size: medium. Priority: Medium.
Phase status lives in §6.1 of this issue body, and nowhere else.
1. Why
Every page shares one card, docs/public/og-image.jpg (99,885 bytes, 1200×630), a screenshot of the landing. Its tags are written once, site-wide, in docs/astro.config.mjs:154-165 (og:image, og:image:type image/jpeg, twitter:image, one PREVIEW_ALT). Three faults:
- Apps that show a link preview as a square crop it from the centre (x 285–915 of 1200). That cuts the headline and the branch graph.
- Its URL never changes (
https://northguild.dev/worktree/og-image.jpg), so Facebook keeps the old copy after a redraw. - A shared command page shows the landing, not its own title.
The same work is done for GMT (northguild/gmt#478, closing northguild/gmt#456) and northguild.dev (northguild/northguild.dev#22). Both are local clones and were read for this plan: northguild.dev/scripts/build-og-card.mjs (a committed, deterministic script, never run in the build; sharp + canvaskit-wasm; palette PNG) and gmt/apps/dox/src/lib/og-art.ts, og-cards.ts, og-canvaskit.ts, og-image-version.ts and src/pages/og/[...route].ts (a build-time route per card, a post-build ?v= rewrite). They are notes, not a design to copy blindly.
2. Constraints
- The crop. Everything a reader must read sits inside x 285–915 with a margin. Outside the square is decoration a crop may lose.
- 300 KB. WhatsApp skips a preview over 300 KB, so every card is a palette PNG under 300 KB (307,200 bytes).
- Contrast. Text on a card is at least 4.5:1 against the brightest pixel behind it.
- No title is cut. A page title takes at most two lines; one that does not fit fails the build. Never shorten it with
…. - Deterministic art. The art script gives the same bytes every run and is never part of
pnpm docs:build. - Theme. A panel, if there is one, has the theme's bevelled corners (
corner-shape: bevel), not rounded ones. - The docs site is static and holds no secret (
context/stack.md). No new runtime dependency reaches the CLI package; the new ones aredocsdevDependencies. - The crawl surface stays as is.
/dox/staysnoindexand out of the sitemap andllms.txt; the 404 keeps its no-canonical, no-JSON-LD rules.
3. Decisions
D1. The art (the dark ground and the hero's branch graph, no text) is drawn by a committed script, docs/scripts/build-og-art.mjs, into a committed file docs/src/assets/og-art.png. It is run by hand and not by the build. Rejected: committing the 30 finished cards, because every title or art change would churn 30 binaries; and drawing the art in the build, because the issue asks for a script that is not part of it.
D2. The cards are made in the build, as GMT does: a static route docs/src/pages/og/[...route].ts returns one PNG per card, drawn by docs/src/lib/og-art.ts (CanvasKit, centred text over the committed art) and written as a palette PNG with sharp. Rejected: one committed PNG per page, as in D1; and an image service at request time, because the site is static assets.
D3. Which cards exist. One per page of the 29 at /worktree/og/<slug>.png, where <slug> is the page's route id with / kept (commands/branch.png), plus site.png for the landing, the 404 and /dox/. The landing's card is the site card: "worktree" and "A git worktree for every branch." Every other card is its page title alone, centred in the square. Rejected: a card for /dox/ and the 404, because neither is shared as a page.
D4. Graph source. The art draws the hero's branch graph from docs/src/hero/targets.ts (buildTargets) and docs/src/hero/geometry.ts, with a seeded random source, so the leaf-particle look of the old card stays. Rejected: re-drawing the graph as plain vector lines, because the leaves are what the old card showed and the issue names targets.ts.
D5. The ?v= hash is the first 12 hex characters of the PNG's SHA-256 and is written by a small Astro integration on astro:build:done, over the built HTML, as GMT's og-image-version.ts does. Pages and PNGs are made in the same build in no fixed order, so the rewrite has to follow both. Rejected: hashing inside Head.astro, which would render each card twice and depend on module sharing nobody has checked; and a hand-kept version number, which goes stale.
D6. Tags are per page. Head.astro replaces the site-wide og:image and twitter:image entries that astro.config.mjs writes now. og:image:type is image/png, og:locale is en_US (Starlight writes en), and og:image:alt and twitter:image:alt say what the card shows (the site card quotes its line, a page card its title) and never repeat the page title on its own.
D7. The old card goes. docs/public/og-image.jpg is deleted and nothing points at it. A preview a platform already cached keeps its own copy of the old image.
D8. Fonts. Michroma, SIL OFL, as a TTF in docs/src/assets/og-fonts/ with its licence file beside it, as GMT and northguild.dev do; the site's woff2 in docs/public/fonts/ cannot be loaded by CanvasKit. The card's text is Michroma only, so JetBrains Mono is not vendored.
D9. Audit. docs/scripts/audit-dist.mjs replaces its JPEG/1200×630 rules for the share image with rules for the new one (see Phase 5), and each new tag gets its own check, as the issue asks.
4. Design
Art (Phase 1). build-og-art.mjs loads buildTargets from docs/src/hero/targets.ts, places the graph's leaves with a seeded generator inside the square, and draws a bevelled panel behind where the text will sit, with CanvasKit, then writes a palette PNG with sharp. It prints the contrast of the colours the text uses against the brightest pixel behind the text, and fails under 4.5:1 (the check build-og-card.mjs does). Colours are the theme's tokens as RGB triples (docs/src/styles/northguild/tokens.css), because a canvas takes numbers and not CSS variables. targets.ts imports ./geometry without an extension, which Node's type stripping cannot resolve, so Phase 1 gives that one import its .ts extension, as astro.config.mjs already does for its own imports.
Cards (Phases 2–3). og-art.ts takes {kind: "site", line} or {kind: "page", title}, lays the text out in the safe square less a margin (285+28 to 915−28), shrinks a title until it takes two lines at most and throws when the smallest size still takes three, and returns a palette PNG. og-cards.ts is pure: from the docs collection's entries it returns the card per key and the alt text per card. The route has one getStaticPaths entry per key.
Tags (Phase 4). Head.astro already receives starlightRoute.head and filters it; it drops Starlight's and the config's image entries and writes the page's own. The integration, listed before starlight() so every later hook reads the final HTML, appends ?v=<hash> 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 it cannot find.
Audit (Phase 5). Per page: og:image is an absolute https://northguild.dev/worktree/og/<key>.png?v=<12 hex> whose hash equals the built file's, a PNG by its own header, 1200×630, at most 307,200 bytes, with og:image:type image/png, og:image:width and :height saying so; twitter:image equals it; og:locale is en_US; both alts are present and neither equals the page's title; the card for a page is its own, not the site card's, except the landing, the 404 and /dox/.
5. Risks
- Sharp under
allowBuilds: false(pnpm-workspace.yaml). sharp 0.35.5 is in the lockfile through Astro and its prebuilt@img/sharp-darwin-arm64is there, but nothing here has run it with that setting. Phase 1's first act is to prove it loads and writes a palette PNG; the response if it does not is a decision for the user, not a setting flipped on its own. - CanvasKit in the Astro build. The WASM file is found by path in GMT (
og-canvaskit.ts); a bundler that moves it breaks the route. Phase 3'spnpm docs:buildis the proof, andlocateFilethe response. - Build time and memory. 30 cards rendered in the build. GMT renders about 160. The response if it matters is to render each card once and cache the bytes in the module.
- Palette PNG over 300 KB. The graph's leaves are many small shapes. Phase 1 measures; the response is fewer, larger leaves or a smaller palette, never a larger limit.
- Hash rewrite ordering. The sitemap integration here reads each page's built footer; the rewrite changes only two meta tags. Phase 4 runs the existing audit unchanged except for the new rules to show it.
- A title that cannot fit. A future page whose title takes three lines fails the build by design. The message names the page.
6. Phases
6.1 Status ledger
| # | Phase | Status | Depends on | Note |
|---|---|---|---|---|
| 1 | Card art: script, dependencies, committed art | done | — | 1652c06 |
| 2 | Card renderer and card set | done | 1 | 463e6d0 |
| 3 | The /og/ route |
done | 2 | ad1fc68 |
| 4 | Per-page tags and the versioning integration | done | 3 | d4476da |
| 5 | Audit rules, and the old card removed | done | 4 | 0cc4c62 |
| 6 | Documentation | done | 5 | 2ed3960 |
Status is one of not started, in progress, blocked, done. A row goes to in progress when work on
the phase starts, before any code, so an interrupted run leaves a ledger that says what was underway. done
only when the scope landed and both gates passed, and whoever finishes a phase updates the row as part of
the same change as the work — who commits that change is context/git.md's answer, not this
table's.
The Note is one line: what a later session needs in order to understand or resume the Status beside it — what is underway, what remains, what is blocking, or the commit sha where a row is done. Nothing else.
Exactly one table in this document has these columns.
6.2 The phases
Phase 1 — Card art: script, dependencies, committed art
Files: docs/package.json, pnpm-lock.yaml, docs/scripts/build-og-art.mjs, docs/scripts/build-og-art.test.mjs, docs/src/assets/og-art.png, docs/src/assets/og-fonts/Michroma-Regular.ttf, docs/src/assets/og-fonts/Michroma-OFL.txt, docs/src/hero/targets.ts
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md, typescript/rules.md, typescript/anti-patterns.md, tooling/dependencies.md, react/accessibility.md (the contrast rule)
Decisions: D1 the art is a committed script's output, never built; D4 the graph comes from targets.ts with a seeded random; D8 Michroma TTF, OFL file beside it.
Scope: Add canvaskit-wasm and sharp to docs devDependencies, at versions at least two weeks old. Prove sharp loads and writes a palette PNG here. Vendor the font. Give targets.ts's ./geometry import its .ts extension. Write the script and its test: same bytes on two runs, the graph and panel inside x 285–915 with a margin, the contrast figure at least 4.5:1. Run it and commit og-art.png.
Done when: node docs/scripts/build-og-art.mjs run twice leaves docs/src/assets/og-art.png byte-identical; its test passes in pnpm docs:test; the PNG is a palette PNG; pnpm check, pnpm typecheck, pnpm --filter docs typecheck and pnpm docs:build pass.
Phase 2 — Card renderer and card set
Files: docs/src/lib/og-canvaskit.ts, docs/src/lib/og-art.ts, docs/src/lib/og-art.test.ts, docs/src/lib/og-cards.ts, docs/src/lib/og-cards.test.ts
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md, typescript/rules.md, typescript/anti-patterns.md, typescript/error-handling.md, architecture/folder-structure.md, react/accessibility.md (alt text)
Decisions: D2 CanvasKit centred text over the committed art; D3 one card per page plus site, a page card is its title alone; D6 alt text says what the card shows; the title takes two lines at most and a longer one throws.
Scope: renderCard(card) returns a palette PNG under 300 KB of 1200×630 with its text inside the safe square less a margin. ogCards(entries) returns the card per key (site plus every page's), and ogImageAlt(card) its alt. A title that needs a third line throws an error that names the title.
Done when: tests prove, for every one of the 29 pages' real titles read from the docs collection, that renderCard succeeds and returns at most 307,200 bytes; a synthetic over-long title throws; no line's box leaves x 285+margin to 915−margin; ogImageAlt of a page card is not its title alone.
Phase 3 — The /og/ route
Files: docs/src/pages/og/[...route].ts
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md, typescript/rules.md, typescript/anti-patterns.md
Decisions: D2 a build-time static route draws each card; D3 the key set is ogCards's.
Scope: One getStaticPaths entry per key, each a PNG response. Nothing else changes.
Done when: pnpm docs:build writes docs/dist/og/site.png and one PNG per page, each 1200×630 and at most 307,200 bytes; pnpm docs:audit-dist still passes.
Phase 4 — Per-page tags and the versioning integration
Files: docs/src/components/Head.astro, docs/astro.config.mjs, docs/src/lib/og-image-version.ts, docs/src/lib/og-image-version.test.ts
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md, typescript/rules.md, typescript/anti-patterns.md, typescript/error-handling.md, react/accessibility.md (alt text)
Decisions: D5 the hash is written after the build by an integration listed before Starlight's; D6 tags are per page, og:locale en_US, og:image:type image/png, alts that describe the card.
Scope: Head.astro writes each page's og:image, og:image:type, og:image:width, og:image:height, og:image:alt, twitter:image, twitter:image:alt and og:locale, and the config stops writing the old site-wide ones. The integration appends ?v=<hash> and fails on the three cases in §4.
Done when: in docs/dist, getting-started/index.html names og/getting-started.png?v=<12 hex> equal to the first 12 hex characters of that file's SHA-256, on both og:image and twitter:image; the landing, the 404 and dox/index.html name og/site.png; the integration's tests cover its three failures.
Phase 5 — Audit rules, and the old card removed
Files: docs/scripts/audit-dist.mjs, docs/scripts/audit-dist.test.mjs, docs/public/og-image.jpg
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md, typescript/rules.md, typescript/anti-patterns.md
Decisions: D7 the old JPEG is deleted; D9 each new tag gets its own audit rule; D6 the alt never repeats the title.
Scope: Replace the share-image rules at audit-dist.mjs:1768-1808 with the rules in §4's Audit paragraph, one failure line per rule, each with a failing fixture in the test. Delete docs/public/og-image.jpg.
Done when: pnpm docs:build && pnpm docs:audit-dist exits 0; for each new rule a test builds a fixture that breaks only that rule and sees only that failure; git grep -n "og-image.jpg" finds nothing outside context/archive/ and this plan.
Phase 6 — Documentation
Files: context/verify.md, context/stack.md, docs/README.md
Standards: philosophy/ai-agent-behavior.md, philosophy/core-principles.md
Decisions: D1 the art script is by hand; D2 the cards come from the build; D9 the audit's rules.
Scope: Fix the three surfaces in §7 so none still describes one JPEG or lacks the script.
Done when: each row of §7 is true of the tree and git grep -n "og-image" in those three files finds no claim about the JPEG.
7. Documentation
Surfaces checked: every one in context/stack.md's Documentation table.
| Surface | What changes | Phase |
|---|---|---|
context/verify.md |
Audit describes the share image as a 1200×630 JPEG named og-image.jpg; it becomes the PNG per page with ?v=, the locale, the size limit and the alt rules |
6 |
context/stack.md |
the layout's docs/scripts/ line lacks build-og-art.mjs, and docs/src/ lacks the card renderer, the route and the integration |
6 |
docs/README.md |
how to redraw the art (node docs/scripts/build-og-art.mjs) and that cards are made by the build |
6 |
Checked and unchanged: README.md (the package page; no mention of the preview), docs/src/content/docs/ (no page describes the preview image), docs/worker/README.md, docs/evals/README.md, skills/worktree/SKILL.md, docs/src/content/docs/changelog.mdx, context7.json (it indexes the user docs and the skill, not docs/scripts/). docs/** owes no release note (context/release.md), and the new packages are docs devDependencies.
8. Verification
Beyond context/verify.md:
- End to end in a real browser. This feature adds no control to a page; nothing here drives a browser and
context/verify.mdnames none, so the check is §9's after the deploy. - A square crop by eye. Open
docs/dist/og/site.pngand one page card; crop x 285–915 and read the whole text. - Contrast. The art script prints it; the number is at least 4.5.
| Value | What decides it |
|---|---|
| card width and height, 1200 × 630 | the Open Graph large-image convention both reference repos use; GMT's OG_WIDTH/OG_HEIGHT |
| the safe square, x 285–915 | the issue's own figure (a 630-pixel square cut from the middle of 1200) |
| the size limit, 307,200 bytes | WhatsApp skips a preview over 300 KB (the issue) |
the ?v= value |
the first 12 hex characters of the SHA-256 of the built PNG's bytes, computed by node:crypto in the test and not by the integration under test |
| text contrast, at least 4.5:1 | WCAG 2.2, AA for text |
og:locale, en_US |
the Open Graph language_TERRITORY form (the issue) |
| the card's key for a page | the page's route id, from the docs collection |
9. Open questions
- The look needs a person. How the card reads (the leaves' density, the panel, the type size) is a design judgement; Phase 1 and 2 produce a candidate and someone has to approve it. Needs a person. Filed at retirement as Share cards: approve how the card looks #378.
- Previews on real platforms after the deploy: Facebook Sharing Debugger, LinkedIn Post Inspector, X, Slack, Discord, WhatsApp and iMessage each show the card, and a square crop still shows the whole title. Nothing here drives those. Needs a person. Filed at retirement as Share cards: check previews on real platforms after deploy #379.
- Does sharp work with
allowBuilds: false? Unverified; Phase 1 proves it first. If not, the answer changes a setting this plan does not own. Settled by Phase 1 (1652c06): yes. sharp 0.35.5 loads through its prebuilt@img/sharp-darwin-arm64binary and writes a palette PNG; no setting changed. - Does the
/worktree/og/path reach the Worker's assets?docs/wrangler.jsoncservesdocs/.deploy, andstage:deploycopiesdistunderworktree/, so it should;docs/scripts/deploy-smoke.mjsdoes not check it. Whether to add a check there is open. Filed at retirement as Share cards: check /worktree/og/ is served after deploy #380. - Is one card for the landing, the 404 and
/dox/right? D3 says yes; a person may want a card for/dox/. Answered at retirement: yes, one card for all three; D3 stands.
Activity
baldurpan commentedon Nov 29, 2026
Phase 1 (card art) opened under
/feature-implement --allon branch 286-share-cards.baldurpan commentedon Nov 29, 2026
Phase 1 closed
doneat 1652c06 (Gate 2 PASS WITH NOTES after one loopback). Phase 2 (card renderer and card set) opened.baldurpan commentedon Nov 29, 2026
Phase 2 closed
doneat 463e6d0 (Gate 2 PASS WITH NOTES, no loopback). Phase 3 (the/og/route) opened.baldurpan commentedon Nov 29, 2026
Phase 3 closed
doneat ad1fc68 (Gate 2 PASS WITH NOTES, no loopback). Phase 4 (per-page tags and the versioning integration) opened.baldurpan commentedon Nov 29, 2026
Phase 4 closed
doneat d4476da (Gate 1 and Gate 2 each one loopback; Gate 2 PASS). Phase 5 (audit rules, old card removed) opened.baldurpan commentedon Nov 29, 2026
Phase 5 closed
doneat 0cc4c62 (Gate 2 PASS after one loopback). Phase 6 (documentation) opened.baldurpan commentedon Nov 29, 2026
Phase 6 closed
doneat 2ed3960 (Gate 2 PASS after one loopback). Every phase isdone; the feature is ready for/feature-close.fix(docs): check the committed card art by its pixels, not its bytes (#…
test(docs): fail when the renderer's text box leaves the art's TEXT_B…
feat(docs): per-page share cards (#286) (#381)