Open Graph images
A social preview image is generated for every page at build time.
On this page
Every page gets its own 1200×630 preview image, the one social networks and chat apps show when its link is shared. Images are generated during the build, written to og/<page>.png at the root of the site, and referenced with the og:image meta tag, which X and the others read as well, alongside a summary_large_image Twitter card.
Nothing is required to turn this on: it follows the og option, which defaults to true. Pass an object instead to change how the card looks.
| Element | Source |
|---|---|
| Logo and site name | The logo and title options |
| Title | The page title, in a smaller size when it is long |
| Description | The page description, when it has one |
| Folders | The breadcrumb trail, or the path for a top-level page |
| Badges | Language and version, when the site has several |
Colors follow the accent of the site, so a card looks like the page it points to.
Every option is optional, and the ones you leave out keep the defaults below.
zenith({
og: {
layout: 'split',
colorScheme: 'light',
backdrop: 'grid',
logo: { src: './src/assets/card-logo.svg', size: 56, position: 'bottom-left' },
siteName: 'Acme Docs',
},
});layout |
Arrangement |
|---|---|
default |
Text on the left, the logo and the site name in a corner, the folders and badges in the others |
centered |
Everything on the center line, the logo above or below the text |
split |
Text on the left, the logo drawn large on the right |
logo takes the logo of the site, at a height of size pixels, in the corner set by position: top-left, top-right, bottom-left or bottom-right. The centered and split layouts only read whether it is at the top or the bottom. src points to another image, as a path from the project root or from public/, and logo: false leaves it out.
siteName is shown next to the logo: true for the title option, a string for another text, or false for none. It is left out of the home page, whose title already is the site name.
SVG, PNG and JPEG files are supported. In an SVG, currentColor takes the accent.
colorScheme draws the card with the dark or light palette of the site. colors changes any of them, as #rrggbb, #rgb or oklch(L C H):
zenith({
og: {
colors: {
background: '#0b1020',
text: '#ffffff',
muted: '#9ca3af',
accent: '#f97316',
border: '#1f2937',
},
},
});backdrop decorates the card with the accent: glow, grid, dots or none. accentBar: false removes the line along the top edge.
background covers the card with an image of your own, under the backdrop and the text, as a path from the project root or from public/. Pair it with backdrop: 'none' to show it as it is.
The card is set in Geist. font takes other TTF, OTF or WOFF files, but not WOFF2, which satori cannot read. Geist still draws the characters they lack.
zenith({
og: {
font: {
name: 'Inter',
files: [
{ path: './src/fonts/inter-regular.woff', weight: 400 },
{ path: './src/fonts/inter-semibold.woff', weight: 600 },
],
},
},
});The title and the site name use weight 600, the rest 400. The closest weight is picked when one is missing.
description, breadcrumb and badges each take false to leave that part out of every card.
The og field of the frontmatter changes the card of a single page. title and description replace the text of the card without touching the page:
---
title: CLI
og:
title: The zenith command
description: Develop, build and preview a site from a folder of Markdown.
---image replaces the generated card with an image of your own, from the root of the site or as a full URL, and og: false gives the page no image at all.
When the options are not enough, template names a module that draws the card. Its default export receives the page and the resolved options, and returns a tree of elements that satori renders: a subset of HTML and CSS, laid out with flexbox.
zenith({
og: { template: './src/og-card.ts' },
});import { h, type OgTemplateProps } from 'zenith-docs/og';
export default function card({ title, siteName, colors, fontFamily }: OgTemplateProps) {
return h(
'div',
{
style: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
width: '100%',
height: '100%',
padding: 80,
background: colors.background,
color: colors.text,
fontFamily,
},
},
h('div', { style: { fontSize: 28, color: colors.accent } }, siteName),
h('div', { style: { fontSize: 72, fontWeight: 600 } }, title),
);
}h(type, props, ...children) builds an element, and leaves out children that are false, null or undefined. Every element with more than one child needs display: 'flex'.
The template receives:
| Prop | Content |
|---|---|
title |
Title of the page, or the one of its og frontmatter |
description |
Description of the page, unless description is off |
section |
Breadcrumb trail, unless breadcrumb is off |
badges |
Language and version, unless badges is off |
siteName |
Site name, left out on the home page or when siteName is off |
url, lang |
URL path and language of the page |
logo |
The logo, as { src, width, height } with src a data URI |
background |
The background image, in the same shape |
colors |
background, text, muted, accent and border, as hexadecimal colors |
fontFamily |
Family to set the text in |
options |
The og options, with their defaults |
zenith-docs/og also exports defaultTemplate, the built-in card. Call it to keep it for most pages, or to change what it receives:
import { defaultTemplate, type OgTemplateProps } from 'zenith-docs/og';
export default function card(props: OgTemplateProps) {
return defaultTemplate({ ...props, badges: [...props.badges, 'Beta'] });
}One image is generated per page, per language and per version, each with its own title and badges. A French page of the previous version is previewed by /og/fr/v1/installation.png, labelled Français and v1.
Untranslated pages are covered too: they fall back to the default language, so their card carries the text that is actually served.
Rendering is done in-process with satori and a WebAssembly build of resvg, with no browser and no network. Count about 90 ms per image, and a second of setup for the first one.
Turn it off if you do not need it:
zenith({
title: 'My Docs',
og: false,
});With og: false, no image is generated and no meta tag is added, except for pages that set an image in their frontmatter.