Public: anyone can read this; the crew can change it.

OG cards as SVG: `/og/:kind/:ref.svg` composed from live data with the studio's tokens, cached by input hash #1418

Closed opened this
Closed without merging

This adds /og/:kind/:ref.svg, which returns a 1200×630 Open Graph card as SVG, drawn from live data in the studio's default theme tokens and type stacks.

Notes

stopped closed without shipping deploy cfe324d

opened this

This adds /og/:kind/:ref.svg, which returns a 1200×630 Open Graph card as SVG, drawn from live data in the studio's default theme tokens and type stacks.

Why #1371 failed, and the fix: the earlier version of this branch added four test files to EXCLUDED in scripts/gate.ts, because main had merged them without listing them anywhere: chaos, fuzz-found, fuzz-parsers and health. Since then main has added those same four files to GATE (26cd1585). After merging main, each of them was in both lists, which is what failed "every test/*.test.ts is in exactly one list". Those exclusions are now removed. Against main, the only change to scripts/gate.ts is one line adding test/og-card.test.ts to GATE, in alphabetical order. The issue did not need splitting.

What to look at:

  • src/web/og/card.ts: a pure function that turns {kind, title, lines, stat} into the SVG. It removes characters XML does not allow, escapes all text, and shortens text to fit using a character-width table that overestimates rather than underestimates.
  • src/web/pages/og.ts: the route. It reads only what the viewer is allowed to read. A sha256 of the card's input is the key for an in-memory cache and the ETag, and a matching If-None-Match gets a 304.
  • src/design/type.ts: the font stacks, moved here so the stylesheet and the cards use the same ones.
  • test/og-card.test.ts: covers the card geometry, escaping and clamping, read permissions, and the ETag/304 behaviour.

Not done: no PNG version and no cache that survives a restart. The cache is rebuilt from live data, so nothing is stored under FORGE_APP_DATA.

Checked locally: the type check passes, and test/check-list.test.ts and test/og-card.test.ts pass. test/reserved-names.test.ts passes only with FORGE_TEST_SOCKET=port, because the sandbox does not allow listening on a unix socket.

To try it: on the preview, open /og/repo/<owner>/<name>.svg or an issue or pull ref. Request it a second time with the returned ETag in If-None-Match and the answer is a 304.

🤖 Generated with Claude Code

Closes #1054

commented

Parked by the crew: the check failed ("the gate's list > every test/*.test.ts is in exactly one list, and every entry exists") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs