Repository navigation
feat(plugins): add @docubook/plugin-og-image for per-page social cards - #493
Conversation
A 1200×630 OpenGraph card for every page, rendered at build time from its frontmatter with Takumi (@takumi-rs/core). Authors write nothing extra: transformFrontmatter points frontmatter.image at the page's card, and flame's SEO code turns it into an absolute og:image. - injectHead adds og:image:width/height/type/alt, and og:image on the landing page when meta.ogImage does not set one - onEnd reads every page's frontmatter, so pages served from flame's page cache still get their card; it renders only cards whose inputs changed, deletes cards of removed pages, and records the result in .docu/og-image.json - the file name hash covers only inputs flame's page cache also sees, so cached HTML never points at a missing card - layouts are Takumi node trees; page text only lands in text nodes - handleRequest renders cards on demand in flame dev - the build warns about characters no loaded font can draw Version 0.1.0, published by hand before merge: npm trusted publishing cannot create a new package. check-release-plan expects the plugin as a patch on a core major, like the Algolia plugin.
- new Social Images page (getting-started/og-image) in the sidebar after Plugins: install, layouts, per-page image and og overrides, options, fonts for other scripts, caching, and flame dev - frontmatter.mdx documents the og field and that image is optional with the plugin; configuration.mdx links it from meta.ogImage - plugins.mdx lifecycle: transformFrontmatter runs after compileMdx and before the SEO tags, not before compileMdx - the docs site and the project template ignore .docu/og-image.json (flame patch changeset for the template)
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
ℹ️ One plugin-interaction bug can break
og:imagein production. Everything else checks out.
Reviewed changes
Initial review (mode: standard) of the new @docubook/plugin-og-image package and the flame docs and .gitignore changes that come with it. Overall: well-tested and carefully matched to flame. Base-path rules, docsIndexWritable, the onEnd page list, pluginsStamp() cache invalidation and the root-index exclusion all match flame's code. Top priorities: (1) the card name must come from one frontmatter source, (2) the CodeQL check is red.
- Plugin hooks:
transformFrontmatterpointsimageat./assets/og/<slug>.<hash>.png.injectHeadadds size, type and alt tags, plus an absoluteog:imageon the landing page.onEndrenders missing or stale cards.handleRequestserves cards inflame dev. - Incremental publishing:
publish.tskeeps a manifest in.docu/og-image.json. It re-renders only cards whose render hash changed or whose file is missing, and deletes only files listed in the previous manifest. Deletion is guarded byisInside(cardDir, …). - Renderer: Takumi native module, loaded lazily. The logo and fonts are passed as bytes, never fetched. Missing glyphs are detected by comparing each character with the notdef box.
- Options and site mirroring: strict option validation, and logo and font paths must stay inside the project.
site.tsmirrors flame'snormalizeBasePath/canonicalBasePath/resolveDeployPath, and the tests pin it to flame's own functions andbuildSeoMeta. - Flame docs and release plan: new Social Images page, the
ogfrontmatter field, a lifecycle diagram fix, the template's.gitignore, and acheck-release-plan.mjsscenario for the plugin's flame peer.
ℹ️ The CodeQL check fails on regexes copied from flame
The CodeQL check is red with 3 "polynomial regular expression" alerts at plugins/og-image/src/site.ts lines 62, 112 and 136. These are the same /^\/+|\/+$/g and /\/+$/ patterns flame already uses in base-path.ts and seo.ts. The input is docu.json, which the site author writes, so there is no real ReDoS exposure. The alerts still need to be dismissed, or the check stays red. Rewriting the patterns would also clear it, but they should stay identical to flame's.
Technical details
# CodeQL js/polynomial-redos alerts on mirrored base-path regexes
## Affected sites
- plugins/og-image/src/site.ts:62 — `path.replace(/^\/+|\/+$/g, "")` (mirror of flame base-path.ts:32)
- plugins/og-image/src/site.ts:112 — `.replace(/\/+$/, "")` on `meta.baseURL` (mirror of flame seo.ts:39)
- plugins/og-image/src/site.ts:136 — `r.href?.replace(/^\/+|\/+$/g, "")` on `routes[].href`
## Required outcome
- The CodeQL check is green before merge, or the alerts are dismissed with a reason (input comes from the project's own docu.json).
## Open questions for the human
- Dismiss the alerts ("won't fix: trusted config input"), or trim slashes without a regex here and in flame together so the two copies stay identical?claude-opus-5-5 | 𝕏
CodeQL flagged the `/\/+$/` patterns in site.ts (base path, baseURL and route hrefs from docu.json) as polynomial on long runs of `/`. A linear trimSlashes() replaces them; the base-path parity tests against flame still pass, and a new test runs 100,000 slashes through it.
There was a problem hiding this comment.
ℹ️ No new issues in this commit. The CodeQL check is green again. The earlier
og:imagefile-name thread onindex.ts:251is still open.
Reviewed changes
Incremental review (mode: standard) of 065bfca, the one commit since the last review at 6dd2d2f. It is a fix for the CodeQL alerts.
- Linear slash trimming: Added
trimSlashes(value, endOnly)tosite.ts. It replaces the/^\/+|\/+$/gand/\/+$/regexes innormalizeBasePath,domainOf,resolveSiteandsectionFor. The output is the same as before, including all-slash input ("///"→""). Thesite.test.tscases that compare against flame's ownnormalizeBasePath/buildSeoMetastill cover this.sectionFornow also skips a non-stringhref, where it used to throw. - Tests: Added cases for both trim modes and a 100k-slash input. The check runs in microseconds, so the 100 ms limit leaves plenty of room.
The open MEDIUM finding was not touched by this commit, so its thread stays open. transformFrontmatter / injectHead plan the card from the frontmatter after the plugin chain has run, while onEnd plans it from the raw source. Overall: ready once that thread is resolved.
claude-opus-5-5 | 𝕏
transformFrontmatter planned the card from the frontmatter it received, after onLoad and earlier plugins' transformFrontmatter, while onEnd and flame dev planned from the source file. A plugin that changed a title gave the page an og:image file name that onEnd never wrote, so it 404'd in production; flame dev hid it by serving a stale hash. - transformFrontmatter reads the source file synchronously (PluginBuilder types the hook as synchronous) and plans from it, as onEnd does; an image set by the author or an earlier plugin still wins - injectHead reuses the card transformFrontmatter linked for the slug, so a later plugin changing the title keeps the size and alt tags, and one replacing the image drops them - README and the Social Images page say the card uses the written title Four new plugin tests fail on the previous code. A flame build of the template with a plugin that rewrites titles in onLoad and transformFrontmatter writes every file its pages link to.
There was a problem hiding this comment.
✅ No new issues found. The open
og:imagefile-name finding is fixed, and all checks are green.
Reviewed changes
Incremental review (mode: standard) of ef3dce1, the one commit since the last review at 065bfca. Overall: READY. No findings are left open.
- One frontmatter source for every hook:
transformFrontmatternow plans the card fromreadFrontmatterSync(site.docsDir, ctx.slug), which is the same source-file read thatonEndandhandleRequestuse. The file name infrontmatter.imagetherefore always matches the fileonEndwrites. The read is synchronous becausePluginBuilder.transformFrontmatteris typed=> Record<string, unknown> | void(plugin.ts:206). Animageorog: falseon the incoming frontmatter still makes the plugin skip the page, and so does the same field in the source. injectHeadreuses the linked card: alinkedmap keyed by slug replaces re-planning fromctx.frontmatter. I checked the hook order in flame.build.ts/build.impl.tsrunrunTransformFrontmatterChainbeforecollectHeadfor each page. In dev, the builder lives for the whole process, anddocsCacheis module-scoped (server-routes.ts:92), so a cached page still finds its map entry. A later plugin that changes the title keeps the tags; one that replacesimagedrops them.- Shared parser: Moved gray-matter parsing into
parseFrontmatter, whichreadFrontmatterandreadFrontmatterSyncboth use. - Tests and docs: Added four
plugin.test.tscases, including the one the earlier review described (Setup · Acmefrom the chain vs.Setupin the source). The README and the Social Images page now explain that the card shows the title as written in the file, and thatog.titlechanges it.
claude-opus-5-5 | 𝕏

Summary
New official plugin
@docubook/plugin-og-image: every page gets its own 1200×630 social preview card, rendered at build time from its frontmatter. Authors write nothing extra. A page withtitleanddescriptiongets its card;image:in frontmatter is only needed to override it.card(default)minimalColours follow
themes.colors, the logo comes fromnavbar.logo.src, and the section is the page's top-level sidebar group.How it works
transformFrontmattersetsimage: ./assets/og/<slug>.<hash>.pngon pages without an image. Flame's own SEO code resolves it againstmeta.baseURLand the docs prefix, so there is exactly oneog:imageper page. The test suite checks this against flame'sbuildSeoMetafor the default prefix, a root deployment, a GitHub Pages project site and a custom prefix.injectHeadaddsog:image:width,og:image:height,og:image:typeandog:image:alt. On the landing page it also addsog:image, unlessmeta.ogImagesets one.onEndreads every page's frontmatter itself. Since perf(flame): keep the page cache when docu.json lists plugins #491, per-page hooks skip cached pages, butonEndstill sees all of them. It renders only cards that are missing or out of date, deletes cards of removed pages, and records the render hash of each file in.docu/og-image.json. A build where nothing changed writes no images.docu.json, page text. Logo, font and theme bytes only trigger a re-render under the same name. Cached HTML therefore never points at a card that was not written.handleRequestrenders a page's card on demand inflame dev, at the same URL.image:in frontmatter always wins,og: falseopts a page out, andog.title/og.descriptionchange only the card text.onLoadortransformFrontmatterchanges the page but not the card, and the file name the page links to always matches the fileonEndwrites.injectHeadreuses the cardtransformFrontmatterlinked.Renderer: Takumi
Cards are rendered with Takumi (
@takumi-rs/core2.19), a native renderer with prebuilt binaries and no browser. On a 4-vCPU Linux sandbox:render()never fetches. The logo and fonts are read from disk and passed as bytes, andprepare(), which does fetch, is never called.fontsoption adds fonts for other scripts.Options
layout(card|minimal),logo,siteName,pages(docs,index,home),fonts. Unknown keys, remote logos and paths outside the project stopsetup()with a[plugin:og-image]error. A missing or oversized logo is a warning, and cards render without it.Flame changes (patch changeset)
.gitignore, and the docs site's, ignore.docu/og-image.json.getting-started/og-image), theogfrontmatter field, a link frommeta.ogImage, and a fix to the plugin lifecycle diagram (transformFrontmatterruns aftercompileMdx, before the SEO tags).Release plan
The plugin is
0.1.0and public, with no plugin changeset. npm trusted publishing cannot create a new package, so before merging:pnpm --filter @docubook/plugin-og-image publish --access public. Use pnpm soworkspace:^becomes^2.6.0(flame) and^2.2.1(themes-colors). Add--no-git-checksif pnpm refuses to publish from a non-main branch.release.ymlon npmjs.com.scripts/check-release-plan.mjsnow expects the plugin as a patch on a core major, like the Algolia plugin. The docs site does not use the plugin yet; it takes plugins from npm, so that is a follow-up after the publish.Verification
tsc,oxlintand Prettier pass.turbo lint typecheck testfor flame and both plugins: 14 of 14 tasks pass.check-release-plan.mjs: 6 of 6 scenarios. The pre-push hook passes.flame buildof the project template with the built plugin, on Bun, Node and Deno 2.9.6: 5 cards on a cold build, 0 rendered and 5 unchanged on a warm one. Everyog:imagein the HTML points at a file in the output; a page with its ownimagekeeps it, andog: falsefalls back tometa.ogImage.flame dev: a card URL returnsimage/png, a stale hash returns the page's current card, an unknown slug returns 404, and otherassets/requests still reach flame.onLoadandtransformFrontmatter: everyog:imagein the HTML points at a file in the output./\/+$/patterns as polynomial on long runs of/; a lineartrimSlashes()replaces them.pnpm pack: the tarball holdsdist,README.mdandLICENSE, with peer@docubook/flame ^2.6.0.