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

OG renderer: SVG composed from data, rasterized to PNG with resvg, cached by input hash #536

Closed opened this in answer to
Closed without merging

Adds src/web/og/, which composes an SVG from typed inputs, rasterizes it to a 1200×630 PNG with the resvg binary, and serves it at GET /og/:kind/:slug.png?t=…&s=…. bun x tsc --noEmit is clean and bun test test/og.test.ts passes (7 pass, 1 skipped). I did not run the full check from forge.json locally.

Notes

stopped closed without shipping deploy b4b40cc

opened this

Adds src/web/og/, which composes an SVG from typed inputs, rasterizes it to a 1200×630 PNG with the resvg binary, and serves it at GET /og/:kind/:slug.png?t=…&s=…. bun x tsc --noEmit is clean and bun test test/og.test.ts passes (7 pass, 1 skipped). I did not run the full check from forge.json locally.

  • Composition: compose.ts builds the SVG from the kind, title and subtitle (the kinds are OG_KINDS). Every input is escaped, and the output is deterministic. Titles wrap to a bounded number of lines with an ellipsis at the cut.
  • Rasterizing: raster.ts runs resvg, found through FORGE_RESVG or PATH. It is not a package, so there is no new dependency. If resvg is missing, the request gets a 503, never a made-up picture.
  • Cache: render.ts keys on the sha256 of the inputs. Equal inputs rasterize once, concurrent identical requests share one render, and failures are not cached.
  • Route: route.ts returns 404 for an unknown kind, a missing title or control characters. A good response is image/png, immutable, with an ETag and 304 on If-None-Match. The route is registered in src/http/server.ts and test/og.test.ts is added to the check list in forge.json.
  • Tests: compose escaping and determinism, wrapping, cache and single-flight behaviour, route 404/200/304/503 with a stand-in renderer, and a real render of every kind. That one checks the PNG header size, that it decodes, and a warm response under 50 ms.

The real-render test is skipped on hosts without resvg, and this clone has none, so it has not run here. The stand-in tests do run.

I did not use a wasm build or embed fonts. It depends on the host's resvg and its fonts, which forge.json does not install. I also dropped the Chromium fallback because it takes about 14 s a picture.

To try it, install resvg and open /og/repo/x.png?t=Hello&s=World.

🤖 Generated with Claude Code

Closes #452

2 earlier comments
commented

Adds src/web/og/: it composes an SVG from typed inputs, rasterizes it to a 1200×630 PNG with the resvg binary, and serves it at GET /og/:kind/:slug.png?t=…&s=….

Check fix: adding test/og.test.ts pushed check.run in forge.json past the forge's 1000-character limit. I shortened it with two shell globs, test/fork*.test.ts and test/crew-[lsw][air]*.test.ts. Each glob matches exactly the files it replaced, so the set of tests run is unchanged. The command is now 958 characters.

Verification: bun x tsc --noEmit is clean. I ran bun run check once, with the fork* glob in place. It passed: 652 tests across 43 files, in 3 shards. The crew glob came after that run. I confirmed it lists the same three files and re-ran tsc, but I did not re-run the full check.

  • Composition: compose.ts escapes every input and gives the same output for the same input. Titles wrap to a bounded number of lines and end in an ellipsis where they are cut.
  • Rasterizing: raster.ts runs resvg, found through FORGE_RESVG or PATH. It adds no dependency. If resvg is missing, the request gets a 503.
  • Cache: render.ts keys on the sha256 of the inputs. Equal inputs rasterize once, concurrent identical requests share one render, and failures are not cached.
  • Route: route.ts returns 404 for an unknown kind, a missing title or control characters. A good response is image/png, immutable, with an ETag and a 304 on If-None-Match. The route is registered in src/http/server.ts.
  • Tests: compose escaping and determinism, wrapping, cache and single-flight behaviour, and the route's 404/200/304/503 cases using a stand-in renderer. A test that renders every kind for real checks the PNG header size, that it decodes, and a warm response under 50 ms.

The real-render test is skipped on hosts without resvg, and this clone has none, so it has not run here.

Not done:

  • I used the host's resvg binary instead of a wasm build.
  • No fonts are embedded. Text uses whatever fonts the host's resvg finds, and forge.json does not install them.
  • No Chromium fallback, because it takes about 14 s a picture.

To try it, install resvg and open /og/repo/x.png?t=Hello&s=World.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed it. The only conflict was in forge.json, and the full check passes locally: 665 tests across 44 files.

main had changed check.run to list tests by bare name after -- (for example crew crew-wrapup …). I took that form and appended og. The globs I used earlier to get under the 1000-character limit (test/fork*.test.ts and test/crew-[lsw][air]*.test.ts) are gone, since the bare-name list is shorter and names each file exactly.

The OG renderer is unchanged: SVG composed from data, rasterized with resvg, cached by a hash of the inputs, and served at /og/:kind/:slug.png. The test that renders every kind for real is still skipped on hosts without resvg, and this clone has none, so it has not run here.

To try it: install resvg and open /og/repo/x.png?t=Hello&s=World.

🤖 Generated with Claude Code

commented

Parked by the crew: main moved under it 2 times and the branch could not be brought up to date (forge.json)

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs