Skip to content

Commit b57de2b

Browse files
committed
fix: add language in the canonical url
1 parent db30a06 commit b57de2b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/[lang]/[[...mdxPath]]/page.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react-hooks/rules-of-hooks -- false positive, useMDXComponents are not react hooks */
22

33
import { SuggestPattern } from '@/app/_components/suggest-pattern'
4+
import { BASE_URL } from '@/app/_constants/project'
45
import { JsonLd, generateArticleSchema } from '@app/_components/json-ld'
56
import { generateBreadcrumbSchema } from '@app/_utils/generate-breadcrumb-schema'
67
import { Metadata } from 'next'
@@ -13,10 +14,11 @@ export async function generateMetadata(props: PageProps): Promise<Metadata | nul
1314
try {
1415
const params = await props.params
1516
const { metadata } = await importPage(params.mdxPath || [], params.lang)
16-
17-
// Check if this is the homepage
1817
const isHomepage = !params.mdxPath || params.mdxPath.length === 0
1918

19+
// Include the language prefix in the canonical path
20+
const canonicalPath = `/${params.lang}${params.mdxPath ? `/${params.mdxPath.join('/')}` : ''}`
21+
2022
const ogImage = {
2123
url: isHomepage
2224
? '/og/opengraph-image.png'
@@ -31,6 +33,9 @@ export async function generateMetadata(props: PageProps): Promise<Metadata | nul
3133
openGraph: {
3234
...metadata.openGraph,
3335
images: [ogImage]
36+
},
37+
alternates: {
38+
canonical: `${BASE_URL}${canonicalPath}`
3439
}
3540
}
3641
} catch (e) {

0 commit comments

Comments
 (0)