Skip to content

fix(og-image): load fonts via TTF files instead of @fontsource WOFF#167

Merged
marc0olo merged 1 commit into
mainfrom
infra/fix-og-image-fonts
Apr 29, 2026
Merged

fix(og-image): load fonts via TTF files instead of @fontsource WOFF#167
marc0olo merged 1 commit into
mainfrom
infra/fix-og-image-fonts

Conversation

@marc0olo
Copy link
Copy Markdown
Member

@marc0olo marc0olo commented Apr 29, 2026

Problem

The social preview image (og-image.png) was generating with no text — just the background, accent bar, and footer dot. All text was invisible.

The root cause is a format mismatch between the web and the build tool:

  • @fontsource packages ship WOFF/WOFF2 only — these are browser delivery formats, compressed wrappers around TTF data designed for efficient HTTP transfer. Browsers have built-in decoders for them.
  • resvg-js uses fontdb, a Rust system font library that only supports TTF/OTF. fontdb explicitly lists non-TTF support as a non-goal — it is a system-level renderer, not a browser, and the OS font system only uses TTF/OTF. Passing WOFF files to fontFiles silently fails with no error; text simply does not render.

The original plugin code also passed fonts via a fontBuffers option that does not exist in the resvg-js 2.6.2 API (it was added later, and only for the Wasm build path). This meant fonts were never loaded at all.

Fix

Commit Inter v4.1 (Regular/Medium/SemiBold/Bold, from rsms/inter) and Newsreader Variable (from google/fonts) as TTF files in src/fonts/, and point the plugin's fontFiles option at those.

The @fontsource packages are untouched — they continue to serve WOFF2 to the browser via the CSS imports in astro.config.mjs. The TTF files are used exclusively at build time to render the PNG and are not included in the deployed site.

Changes

  • src/fonts/ — five TTF files committed (~1.6 MB total, build-time only)
  • plugins/astro-agent-docs.mjsfontFiles now points at src/fonts/; removed the non-existent fontBuffers option

resvg-js uses fontdb (a Rust system font library) which only supports
TTF/OTF. WOFF/WOFF2 are browser-only delivery formats and fontdb
explicitly lists non-TTF support as a non-goal. Passing WOFF files via
fontFiles silently fails — text renders as invisible in the generated PNG.

Commit Inter v4.1 (Regular/Medium/SemiBold/Bold) and Newsreader Variable
TTF files to src/fonts/ and point the plugin at those. The @fontsource
packages remain in dependencies — they still serve WOFF2 to the browser
via the CSS imports in astro.config.mjs. The TTF files are build-time
only and are not included in the deployed site.
@marc0olo marc0olo merged commit 0b0cc7c into main Apr 29, 2026
1 check passed
@marc0olo marc0olo deleted the infra/fix-og-image-fonts branch April 29, 2026 16:46
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