Skip to content
TrademarkTrademark
Docs
Components

OgCard

Updated: May 9, 2025
View on GitHub

The OgCard component displays rich link previews for URLs by fetching and rendering Open Graph metadata. It's perfect for showcasing external links with preview images, titles, and descriptions.

Mock data

Instead of fetching Open Graph data from a URL, you can directly provide the data to display.

Direction

The OgCard component supports different layout directions.

Size

The OgCard component supports different sizes.

Conditional rendering

You can hide each element of the OgCard component by setting its prop value to false.

Custom style

The OgCard extends the Card component, so you can use all Card props to customize its appearance.

Required API routes

To use OgCard with automatic Open Graph fetching, your application must expose two routes: one that fetches a page's metadata, and one that serves its image from your origin. In a Next.js app, both are ready-made in @once-ui-system/core/next, with SSRF protection built in:

See OG route handlers for their options. Outside Next.js, build the routes on handleOGFetch and handleOGProxy.

OgCard calls /api/og/fetch and /api/og/proxy by default. If your routes live elsewhere, wrap the app in OgRoutesProvider:

The optional /api/og/generate route renders social images for Meta.generate; it is not needed by OgCard.

Service configuration

Use serviceConfig to point a single OgCard at custom API routes (it takes precedence over OgRoutesProvider) or to transform proxied image and favicon URLs. Pass pre-fetched data with ogData to skip the fetch entirely.

API reference

Type
Default
url
The page to preview. Its Open Graph data is fetched and rendered.
string—
sizes
The sizes attribute for the preview image.
stringnumber
320px
unoptimized
Skip the framework image optimizer.
booleanfalse
size
Card scale.
lms
m
ogData
Supply the data yourself instead of fetching it.
Partial<OgData>null
—
direction
Image above the text, or beside it.
columnrowcolumn-reverserow-reverse
column
serviceConfig
Where to fetch the Open Graph data from.
OgServiceConfig{}
title
Override the fetched title, or false to hide it.
stringfalse
—
description
Override the fetched description, or false to hide it.
stringfalse
—
favicon
Override the fetched favicon, or false to hide it.
stringfalse
—
image
Override the fetched image, or false to hide it.
stringfalse
—
cardUrl
Override the displayed link text, or false to hide it.
stringfalse
—
…and every FlexProps propinherited—
…and every CardProps propinherited—

OgServiceConfig

Type
Default
fetchOgUrl
Endpoint for fetching OG metadata.
stringOgRoutesProvider's fetch, or '/api/og/fetch'
proxyOgUrl
Endpoint for proxying external assets.
stringOgRoutesProvider's proxy, or '/api/og/proxy'
proxyImageUrl
Transform OG image URLs before rendering.
(url: string) => string—
proxyFaviconUrl
Transform favicon URLs before rendering.
(url: string) => string—

Notes

  • The component automatically fetches favicons for the domain
  • Images are proxied through an API endpoint to avoid CORS issues
  • You can overwrite the default props by providing static values
  • You can set any value to false to disable it
Edit this page on GitHub