← buildlog og

Dynamic OG images for SvelteKit

Set it in +page.svelte with svelte:head using data from your load function. The API returns a 1200×630 PNG, cached at the edge.

<!-- src/routes/blog/[slug]/+page.svelte -->
<script>
  export let data
  const og = 'https://og.sadana.app/api/og?' + new URLSearchParams({ title: data.title, subtitle: data.description, site: 'yourblog.dev' })
</script>
<svelte:head>
  <meta property="og:image" content={og} />
  <meta name="twitter:card" content="summary_large_image" />
</svelte:head>

Because the image is an external URL, this works with adapter-static and prerendering.

Preview

Example OG image for SvelteKit

Parameters

title     required, up to 200 chars
subtitle  optional
site      optional footer text
theme     light | dark (Pro)
key       Pro license key (removes watermark)

Check it

After deploying, paste a URL into a card validator (e.g. opengraph.xyz) or share it in a private Slack/Discord channel. Social crawlers cache images, so change the URL (e.g. add &v=2) to force a refresh.

Try the generator

Other frameworks

Next.js · Astro · Hugo · WordPress · Ghost · SvelteKit · Nuxt · Eleventy (11ty) · Jekyll · Docusaurus · plain HTML