Charon
Docs menu

Social cards

Set og and the build draws a 1200 × 630 PNG at <route>/og.png for each page. The card shows the site name, the page title, its description and its address. Set a site URL too, since crawlers need the card's full address.

Cards need satori and @resvg/resvg-js:

npm install satori @resvg/resvg-js

From the CLI #

Pass a font, and a second one for a bold title:

charon build docs --site-url https://acme.dev \
  --og-font fonts/inter-400.woff --og-font fonts/inter-700.woff

Or put them in charon.json, with colors if you like:

{
  "og": {
    "fonts": [
      { "path": "fonts/inter-400.woff" },
      { "path": "fonts/inter-700.woff" }
    ],
    "background": "#0a0a0a",
    "foreground": "#f5f5f5",
    "muted": "#8a8a8a"
  }
}

From Vite #

Give each font a path from the Vite root, or its data:

import { readFileSync } from 'node:fs'

docs({
  name: 'Acme Docs',
  siteUrl: 'https://acme.dev',
  og: {
    fonts: [
      {
        name: 'Inter',
        weight: 400,
        data: readFileSync('fonts/inter-400.woff'),
      },
      { name: 'Inter', weight: 700, path: 'fonts/inter-700.woff' },
    ],
    background: '#0a0a0a',
  },
})

Fonts #

  • Use TTF, OTF or WOFF. Satori cannot read WOFF2, so the build refuses it.
  • The first font sets the family. Without a weight, the first font is 400 and the rest are 700.
  • Add a 700 weight for a bold title.

Options #

Key Sets
fonts one or more fonts; required
background the background; #0a0a0a
foreground the title; #f5f5f5
muted the rest of the text; #8a8a8a

In your template #

The default template puts the card in {{meta}}. In your own, use {{meta}} or write the tag yourself:

<meta property="og:image" content="{{image}}" />

Last updated