# Social cards

Turn on `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 in JetBrains Mono, which charon ships. Set a site URL too, since
crawlers need the card's full address.

Cards need `satori` and `@resvg/resvg-js`:

```sh
npm install satori @resvg/resvg-js
```

## From the CLI

```sh
charon build docs --site-url https://acme.dev --og
```

Or set it in `charon.json`:

```json
{ "og": true }
```

## From Vite

```ts
docs({ siteUrl: 'https://acme.dev', og: true })
```

## Your own font and colors

Pass an object instead of `true`. From the CLI, give a font, and a second one
for a bold title:

```sh
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:

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

In Vite, give each font a `path` from the Vite root, or its `data`:

```ts
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',
  },
})
```

Leave out `fonts` to keep JetBrains Mono and change only the colors.

## 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.
- The shipped JetBrains Mono covers Latin only. For titles in other scripts,
  pass a font that has them.

## Options

| Key          | Sets                            |
| ------------ | ------------------------------- |
| `fonts`      | your fonts; JetBrains Mono      |
| `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:

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