Skip to content

Commit

Permalink
fix: i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
juliankoehn committed Jan 6, 2025
1 parent ce0882e commit 4e3fd53
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/app/(frontend)/[locale]/(pages)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ export async function generateMetadata({
const { isEnabled: draft } = await draftMode();
const page = await getPage(slug, locale, draft);

// Construct the URL path
const path = Array.isArray(slug) ? slug.join("/") : "/";
const url = `/${locale}/${path}`;

const ogImage =
typeof page?.meta?.image === "object" &&
page?.meta?.image !== null &&
page?.meta?.image &&
"url" in page.meta.image &&
`${page.meta.image.url}`;

// Create language alternatives directly from i18n config
const languages: Record<string, string> = {
en: `/en/${path}`,
de: `/de/${path}`,
};

// check if noIndex is true
const noIndexMeta = page?.noindex ? { robots: "noindex" } : {};

Expand All @@ -49,9 +59,13 @@ export async function generateMetadata({
]
: undefined,
title: page?.meta?.title || "Payload",
url: Array.isArray(slug) ? slug.join("/") : "/",
url,
}),
title: page?.meta?.title || "Payload",
alternates: {
canonical: url,
languages,
},
...noIndexMeta, // Add noindex meta tag if noindex is true
};
}
Expand Down

0 comments on commit 4e3fd53

Please sign in to comment.