8000 docs: generate each page's Open Graph image with @jimp/layout by hipstersmoothie · Pull Request #1562 · jimp-dev/jimp · GitHub
[go: up one dir, main page]

Skip to content

docs: generate each page's Open Graph image with @jimp/layout - #1562

Merged
hipstersmoothie merged 1 commit into
sesh/jimp-layout-for-og-imagesfrom
sesh/docs-og-images-with-layout
Nov 25, 2026
Merged

hipstersmoothie merged 1 commit into
sesh/jimp-layout-for-og-imagesfrom
sesh/docs-og-images-with-layout

Conversation

@hipstersmoothie
Copy link
Copy Markdown
Collaborator

Stacked on #1559 (@jimp/layout); review and merge that first, then retarget this to main.

Every docs page now gets its own Open Graph card, rendered at build time with @jimp/layout, written in JSX. It's the package's own docs using it.

To see the cards, run pnpm build in packages/docs and open dist/og/, e.g. dist/og/methods/draw-rect.png or dist/og/guides/og-images.png.

How it works

  • src/pages/og/[...name].png.ts is a static Astro endpoint. It renders one PNG per docs page at build time.
  • src/og/card.tsx holds the card, written as JSX components with @jimp/layout:
    • a white sticker card with an ink border and hard shadow, like the site's;
    • the JIMP wordmark, cropped from the hand-drawn share banner;
    • a section sticker in the page's colour (method category, Guide, Concept…);
    • the title (in JetBrains Mono for method names), sized down until it fits on two lines;
    • the description, cut at two lines with an ellipsis;
    • an npm install pill, which installs the page's package when it isn't part of jimp, e.g. @jimp/layout.
  • The background is the site's wallpaper: the --jp-wall yellow, the dot grid, and the doodles. The doodles are drawn with plugin-draw's strokePath from the same SVG path data as --jp-wall-doodles in tokens.css.
  • Jimpy is drawn with plugin-draw from the daytime shapes in Jimpy.astro, with a white sticker outline, on a generated paint splash centred behind him. (The banner's art has the splash off to one side, which looked unbalanced at this size.) There's no SVG renderer or WASM involved.
  • src/routeData.ts is a Starlight route middleware. It points og:image and twitter:image at the page's card and adds og:image:width/height.
  • The fonts are Fredoka Medium/Bold and JetBrains Mono Bold, as static Latin subsets (OFL), generated by scripts/og-fonts.sh from a pinned google/fonts commit. They're TTF because loadTTF doesn't read WOFF2.

Choices

  • The type reference shares one card (og/api.png). Its 117 pages are generated and rarely shared, and individual cards would add about 15 MB to the site.
  • The home and 404 pages keep the hand-drawn share-banner.png.
  • Cost: 114 cards, about 13 MB total (about 115 KB each), and roughly 10 s added to the docs build. Each card takes about 100 ms to lay out, draw and encode.

Checked

  • pnpm build in packages/docs passes: astro check reports 0 errors.
  • Every page's og:image points at a file that exists in dist.
  • pnpm install --frozen-lockfile passes.
  • The only new docs dependency is @jimp/plugin-draw (workspace).

Found along the way

Under Astro's "jsx": "preserve", a file needs /** @jsxRuntime automatic */ as well as @jsxImportSource. I've added that to the JSX setup notes in #1559.

🤖 Generated with Claude Code

Every docs page gets its own 1200x630 card, rendered at build time by
src/pages/og/ from a JSX layout (src/og/card.tsx): the site's wallpaper
drawn from the CSS doodles' SVG paths, a sticker card with the page's
section, title, description and install command, and Jimpy on a splash,
drawn with plugin-draw from Jimpy.astro's shapes. A Starlight route
middleware points og:image and twitter:image at it. The type reference's
generated pages share one card, and the home and 404 pages keep the
hand-drawn share banner. Fredoka and JetBrains Mono subsets come from
scripts/og-fonts.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hipstersmoothie
hipstersmoothie merged commit 272a8e9 into sesh/jimp-layout-for-og-images Nov 25, 2026
7 checks passed
@hipstersmoothie
hipstersmoothie deleted the sesh/docs-og-images-with-layout branch November 25, 2026 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0