Open Graph & Twitter Cards
Open Graph and Twitter Cards for social previews - injected by bini-ssg at build time.
Overview
Open Graph and Twitter Cards control how pages look when shared on Facebook, LinkedIn, Slack, and X. Define them in the metadata export on layouts and pages.
- Open Graph: title, description, url, type, images, siteName, locale
- Twitter Cards: card type, title, description, creator, images
- Default image: replace
public/og-image.png(1200×630 recommended) - bini-ssg: injects tags via
getMetadataForRouteduringvite build
Open Graph Overview
Open Graph tags control previews on Facebook, LinkedIn, and Slack.
export const metadata = {
title: 'About Us',
description: 'Learn more about our company and team',
openGraph: {
title: 'About Us - My Bini.js App',
description: 'Learn more about our company and team',
url: 'https://myapp.com/about',
type: 'website',
images: [
{
url: '/og-image.png',
width: 1200,
height: 630,
alt: 'About Us',
},
],
siteName: 'My Bini.js App',
locale: 'en_US',
},
}public/og-image.png and reference it from metadata. Replace it with your own 1200×630 asset.Open Graph Fields
| Field | Type | Injected as |
|---|---|---|
| title | string | og:title |
| description | string | og:description |
| url | string | og:url |
| type | string | og:type |
| images | array | og:image (+ width/height/alt) |
| siteName | string | og:site_name |
| locale | string | og:locale |
Image object fields
| Field | Type | Notes |
|---|---|---|
| url | string | Image URL |
| width | number | 1200 recommended |
| height | number | 630 recommended |
| alt | string | Alt text |
Twitter Cards Overview
Twitter (X) cards control how links appear in the feed. Common types: summary and summary_large_image.
export const metadata = {
title: 'Blog Post',
description: 'A comprehensive guide to Bini.js',
twitter: {
card: 'summary_large_image',
title: 'Blog Post - My Bini.js App',
description: 'A comprehensive guide to Bini.js',
creator: '@bini_js',
images: ['/og-image.png'],
},
}Twitter Card Fields
| Field | Type | Injected as |
|---|---|---|
| card | string | twitter:card |
| title | string | twitter:title |
| description | string | twitter:description |
| creator | string | twitter:creator |
| images | array | twitter:image |
Card types
summary- small imagesummary_large_image- large image (recommended)app- mobile app cardplayer- video / audio
bini-ssg Injection
During vite build, bini-ssg injects OG and Twitter tags into pre-rendered HTML. Existing matching tags are updated in place.
| Metadata | Injected tags |
|---|---|
| openGraph.title | og:title |
| openGraph.description | og:description |
| openGraph.url | og:url |
| openGraph.type | og:type |
| openGraph.images | og:image, og:image:width, og:image:height, og:image:alt |
| twitter.card | twitter:card |
| twitter.creator | twitter:creator |
| twitter.images | twitter:image |
/blog/:slug, metadata is keyed by the route pattern unless you resolve per-URL values yourself.Complete Example
Combined Open Graph and Twitter metadata for a blog post.
export const metadata = {
title: 'Getting Started with Bini.js',
description:
'Learn how to build native cross-platform apps with Bini.js',
openGraph: {
title: 'Getting Started with Bini.js',
description:
'Learn how to build native cross-platform apps with Bini.js',
url: 'https://myapp.com/blog/getting-started',
type: 'article',
images: [
{
url: 'https://myapp.com/images/blog/og.png',
width: 1200,
height: 630,
alt: 'Getting Started with Bini.js',
},
],
siteName: 'My Bini.js App',
locale: 'en_US',
},
twitter: {
card: 'summary_large_image',
title: 'Getting Started with Bini.js',
description:
'Learn how to build native cross-platform apps with Bini.js',
creator: '@bini_js',
images: ['https://myapp.com/images/blog/og.png'],
},
}