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

Closed opened this
Closed without merging

GET /og/:kind/ .svg now returns a 1200×630 Open Graph card for an app, repo, issue, pull or run, built from live data. A card the viewer can't read, an unknown kind or a malformed ref all return the same 404. It adds no dependencies and doesn't touch forge.json.

Notes

stopped closed without shipping deploy 7c26e9d

opened this

GET /og/:kind/<ref>.svg now returns a 1200×630 Open Graph card for an app, repo, issue, pull or run, built from live data. A card the viewer can't read, an unknown kind or a malformed ref all return the same 404. It adds no dependencies and doesn't touch forge.json.

What changed

  • src/web/og/card.ts: a pure function from {kind, title, lines, stat} to SVG. It uses the default theme's colours from src/design/themes.ts and the font stacks, which now live in a new src/design/type.ts; the stylesheet in src/web/style/base.ts reads them from there too. Characters XML forbids are dropped and the rest is escaped. The title wraps to two lines and every line is clamped with an ellipsis. Widths are estimated from a per-character table rounded up from Arial/Helvetica, so a line may stop early but never runs off the card. Only presentation attributes are used, so the forge's default-src 'none' policy leaves the card intact.
  • src/web/pages/og.ts: reads through the same checks the pages use: canRead for repos and apps, mayView for sealed issues and pulls, getRepoRun for runs. Refs:
    • /og/repo/alice/web.svg (the encoded form alice%2Fweb.svg also works)
    • /og/issue/alice/web/12.svg and /og/pull/alice/web/3.svg
    • /og/run/<id>.svg
    • /og/app/<slug>.svg

    Rendered cards are kept in memory, up to 500, keyed by the sha256 of the input. That hash is the ETag, and a matching If-None-Match (weak tags included) gets a 304.

  • Wiring: the route is registered as /og/:kind/*ref in src/http/server.ts, og is added to the reserved names, and the endpoint has a row in docs/STANDARDS.md.

Where this differs from the issue

  • Cache-Control is public, max-age=300 only when a signed-out visitor would get the same card. For a private repo or a sealed thread it is private, max-age=300, so a shared cache never serves one viewer's card to another.
  • The route is *ref rather than :ref.svg so that slashes in a ref can stay unencoded. It still accepts exactly the /og/:kind/<ref>.svg shape.

Look at the gate change. On main, test/check-list.test.ts fails because four test files merged in #1298 and #1302 are in neither gate list: chaos, fuzz-found, fuzz-parsers and health. That would have failed this pull's check, so I added them to EXCLUDED under #1307. Moving them into GATE is #1307's to decide.

Not done here: no page emits the card as og:image yet. Most link previewers don't accept SVG, so that waits for the PNG half and the card designs (#454, #455).

Testing: test/og-card.test.ts is in the gate. It covers:

  • every kind renders well-formed XML at 1200×630
  • a hostile title (<script>, &, 500 characters) is escaped and clamped, checked against widths worked out by hand
  • private and sealed content returns 404 to outsiders and loads for the owner with private caching
  • unknown kinds, the wrong kind (an issue's number under /og/pull/) and malformed refs return 404
  • a repeat request gets a 304, and a changed title gets a new ETag
  • the median of 21 warm requests is under 5 ms

The sandbox here refuses to open a Unix socket, so this test drives the forge's real request path in-process (forgeHttp, with the same security headers serve adds) instead of starting a server. The type check is clean. The og tests and shards, check-list and hollow pass; reserved-names and studio start a server and can't run in this sandbox. I ran the reserved-route check from reserved-names as a separate script and it passes.

To try it: curl -i localhost:3000/og/repo/<owner>/<name>.svg, then send the same request with If-None-Match: <etag> and expect 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