OG images with @beeirl/og-image
Every page gets its own link-preview card, made when the site builds: the logo at the top left and the page's heading anchored to the bottom left, on the brand's background. Long headings get a smaller size and grow upward. Nothing runs at request time, so there is no service, key or deploy step; the cards ship with the site as static files.
How it works: the layout writes a placeholder og:image (/og/<slug>.png) and the card's text in
og-image:title (and optionally og-image:serif) meta tags. After the build, the package renders
each card with Satori and resvg, names the file after a hash of its pixels, rewrites the page's
URLs to it and removes the two meta tags. A changed heading or design gives a new URL, so link
previews refresh. A placeholder without a title fails the build.
Source, README and the brand config's options: https://github.com/beeirl/og-image.
Steps
-
Read the site. Note the framework and whether it builds static HTML; where
<head>is written; every place that writesog:imageortwitter:imagetoday (afterwards exactly one place does); how the canonical URL and the page title are set; the logo as an SVG lockup; the background and heading colours; the heading font the site uses. Done when each is a file path or a value. -
Fonts. The renderer reads TTF, OTF or WOFF, never WOFF2. Commit Latin subsets of the site's own heading font (and the serif, and whatever font the logo's wordmark is set in) next to the site's fonts, with their licences:
pyftsubset Font.ttf --unicodes='U+0020-007E,U+00A0-00FF,U+2010-2027,U+2030-203A' --layout-features='kern,liga,calt' --output-file=...Use the weight the site's headings use, usually regular. -
Install
@beeirl/og-imagefrom GitHub, pinned the way the project pins dependencies (a catalog entry if it has one):github:beeirl/og-image#<tag>, or the tag's full commit SHA (git ls-remote https://github.com/beeirl/og-image <tag>) where only exact pins pass. -
Brand config. Write
og-image.config.mjsat the site's root (the folderastro.configor the build runs in). Paths are relative to it./** @type {import('@beeirl/og-image').BrandConfig} */ export default { background: '#FAF7F2', color: '#1C1917', logo: { path: 'src/assets/logo.svg', height: 56 }, fonts: [{ name: 'Inter Display', path: 'src/assets/fonts/InterDisplay-Regular.ttf', weight: 400 }], heading: { font: 'Inter Display', letterSpacing: -0.03, lineHeight: 1.06 }, }Add
serif(and its font) only when the homepage's tagline has a serif second half. -
Layout. Write these once, in the layout every public page uses:
<meta property="og:image" content="{cardImageUrl(site, pathname)}" /> <meta property="og:image:width" content="1200" /> <meta property="og:image:height" content="630" /> <meta property="og:image:alt" content="{heading}" /> <meta name="twitter:card" content="summary_large_image" /> <meta name="twitter:image" content="{same URL}" /> <meta name="og-image:title" content="{heading}" /> <meta name="og-image:serif" content="{serif line, homepage only}" />cardImageUrlcomes from@beeirl/og-image/meta, which has no dependencies;siteis the canonical production origin, never the request host. The heading is the page title without the brand (Pricing | AcmebecomesPricing), and a page may pass a better one. A blog cover stays on the page; the preview is the card. Remove every otherog:imageandtwitter:image. -
Build step. Astro: add
ogImage()from@beeirl/og-image/astrotointegrations. Any other static output (Hugo, Jekyll, Eleventy, a Next.js or Vite static export): runog-image build <output dir>after the site's build, in the same script that CI and the deploy run. A site rendered per request has no build output to process; say so and stop. -
Check it. Render the homepage, the shortest and the longest heading on the site with
og-image render --title '<heading>' [--serif '<line>'] --out <file>.pngand look at each: nothing clipped, the logo and its wordmark drawn, the heading readable at 400px wide. Then build the site: every page'sog:imageandtwitter:imagepoint at the same/og/<slug>-<hash>.png, which exists, and noog-image:meta tag is left. Done when you have seen the images, not when the code reads right.
Changing the design is a config edit and a rebuild. The new hashes give every card a new URL, so nothing needs purging; a platform that cached an old preview picks up the new image on its next scrape (each platform's debugger forces it sooner).