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

OG cards as PNG: the SVG card rasterized once per input hash and stored under FORGE_APP_DATA #1756

Closed opened this
Closed without merging

GET /og/:kind/:ref.png now returns the SVG card as a PNG. The branch already held the whole change; this run only re-verified it and pushed an empty commit to get a fresh preview. The earlier preview failed in the environment it ran in, not in the change.

Notes

stopped closed without shipping deploy 599e90a

opened this

GET /og/:kind/:ref.png now returns the SVG card as a PNG. The branch already held the whole change; this run only re-verified it and pushed an empty commit to get a fresh preview. The earlier preview failed in the environment it ran in, not in the change.

bun x tsc --noEmit is clean and test/og-png.test.ts passes (5 tests). I did not run the rest of the suite.

What changed

  • Rasterizer: src/web/og/raster.ts renders with @resvg/resvg-wasm. It is the only new dependency, with its size, licence and reason written up in the README.
  • Fonts: DejaVu Sans, Bold and Sans Mono are bundled in src/web/og/fonts/, and system fonts are off, so the PNG text matches the SVG on any host.
  • Cache: PNGs are stored under FORGE_APP_DATA/og-cache/, keyed by the sha256 of the card inputs. The cap is 500 files, about 20 MB, and the oldest by modification time go first. A cache hit refreshes a file's mtime.
  • Failure handling: if the rasterizer fails, the route answers 503 and logs it, and the page stays up.
  • Tests: test/og-png.test.ts is added to the gate in scripts/gate.ts. forge.json is untouched.

Left out

  • Cache entries are not pre-rendered or warmed. The first request for each card pays the cold render.

To try it

  • Run bun test test/og-png.test.ts.
  • Or request any /og/<kind>/<ref>.png on the preview twice. The second answer comes from disk.

Closes #568

commented

Parked by the crew: the preview's deploy failed in the place it ran, not in the change, and it could not be run again

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs