Skip to content

Commit 171c159

Browse files
committed
Wire per-page OG images into App Router metadata
1 parent 11d5287 commit 171c159

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/lib/buildPageMetadata.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ export function buildPageMetadata({
4646

4747
const siteDomain = getDomain(siteConfig.languageCode);
4848
const canonicalUrl = `https://${siteDomain}${pathname}`;
49-
const ogImage = `https://${siteDomain}/images/og-${
50-
section === 'unknown' ? 'default' : section
51-
}.png`;
49+
// OG images are generated per page at build time by
50+
// scripts/generateOgImages.mjs. Pages without a generated card
51+
// (home, errors) fall back to the static section image.
52+
const ogImage =
53+
isHomePage || !title || pathname.startsWith('/errors')
54+
? `https://${siteDomain}/images/og-${
55+
section === 'unknown' ? 'default' : section
56+
}.png`
57+
: `https://${siteDomain}/images/og/${pathname
58+
.slice(1)
59+
.replace(/\//g, '-')}.png`;
5260

5361
const languages: Record<string, string> = {
5462
'x-default': canonicalUrl.replace(siteDomain, getDomain('en')),

0 commit comments

Comments
 (0)