Skip to content
svedocs

SEO and OG

Generate metadata, canonical URLs, JSON-LD, sitemap, robots, and Open Graph images.

svedocs combines global config, frontmatter, route metadata, and generated page data to build each page's SEO tags.

Frontmatter

Markdown
---title: Search and Ask AIdescription: Use local search, Cloudflare AI Search, and Ask AI providers.canonical: https://svedocs.dev/docs/integrations/search-aiimage: https://svedocs.dev/og/docs-search-ai.svgauthor: svedocs teampublished: 2026-05-18updated: 2026-05-18type: articlekeywords: - SvelteKit - documentationrobots: index,followhead: meta: - name: google-site-verification content: page-token links: - rel: alternate href: /feed.xml type: application/rss+xml title: RSS jsonLd: - "@type": FAQPage name: Search FAQ---

If site.url is set, svedocs generates canonical URLs automatically.

Use head for serializable entries that belong only to this page. Global seo.head values come first, followed by entries from page frontmatter. The default root layout renders meta, link, and additional JSON-LD entries automatically.

Metadata

The default root layout renders:

  • <title> and description.
  • Canonical URL.
  • Open Graph and Twitter card tags.
  • JSON-LD for docs pages and single pages.
  • keywords, robots, and serializable head additions.
  • Article author, publish time, and update time when frontmatter provides them.

When building a custom layout, use createPageMetadata(config, page, pages) from svedocs/og. Pass the complete page list so Open Graph locale alternates include only translations that exist.

Sitemap and robots

TypeScriptsrc/routes/sitemap.xml/+server.ts
import { createSitemapResponse } from 'svedocs/og';import config from 'virtual:svedocs/config';import pages from 'virtual:svedocs/pages';export const GET = () => { return createSitemapResponse(config, pages);};

createRobotsResponse(config) provides a matching robots.txt response. Both response helpers return 404 when the corresponding seo.sitemap or seo.robots flag is disabled.

Dynamic OG route

TypeScriptsrc/routes/og/[...path]/+server.ts
import { error } from '@sveltejs/kit';import { createConfiguredOgImageFormat, createConfiguredOgImageRenderer, createConfiguredOgImageTemplate, createConfiguredPageOgImageEntries, createPageOgImagePath, createPageOgImageResponse, isOgImageEnabled} from 'svedocs/og';import config from 'virtual:svedocs/config';import pages from 'virtual:svedocs/pages';export const prerender = isOgImageEnabled(config);const format = createConfiguredOgImageFormat(config);const template = createConfiguredOgImageTemplate(config);export function entries() { return createConfiguredPageOgImageEntries(config, pages);}export const GET = async ({ params }) => { if (!isOgImageEnabled(config)) error(404, 'OG images are disabled.'); const requestPath = `/og/${params.path}`; const page = pages.find((candidate) => createPageOgImagePath(candidate, format) === requestPath); if (!page) error(404, `No OG image found for ${requestPath}`); return createPageOgImageResponse(config, page, { format, renderer: createConfiguredOgImageRenderer(config), ...(template ? { template } : {}) });};

SVG OG routes are portable to edge runtimes. PNG generation is available through the CLI for build-time assets.

Custom root layouts can use createJsonLdScript(value) from svedocs/og when rendering JSON-LD through Svelte {@html ...}. It escapes script-sensitive characters before returning the complete <script type="application/ld+json"> tag.

Build-time OG assets

Configure build-time defaults once:

TypeScriptsvedocs.config.ts
export default defineConfig({ seo: { ogImage: { template: 'default', format: 'svg', outDir: 'static/og', renderer: 'svg' } }});

svedocs build generates these assets after a successful Vite build. Pass --no-og to skip automatic generation for CI jobs that only need the application bundle.

PNG and Satori

Shell
svedocs og --format png --out static/ogsvedocs og --renderer satori --font ./Inter-Regular.ttf --format png

Satori rendering requires explicit font files so output stays deterministic across machines and deployment environments.

Build-time svedocs og and automatic svedocs build generation preserve function templates from svedocs.config.ts. Dynamic routes can use the same template when it is safe for the target runtime; otherwise prefer the default SVG renderer for edge portability.