File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
app/[lang]/[[...mdxPath]] Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable react-hooks/rules-of-hooks -- false positive, useMDXComponents are not react hooks */
2
2
3
3
import { SuggestPattern } from '@/app/_components/suggest-pattern'
4
+ import { BASE_URL } from '@/app/_constants/project'
4
5
import { JsonLd , generateArticleSchema } from '@app/_components/json-ld'
5
6
import { generateBreadcrumbSchema } from '@app/_utils/generate-breadcrumb-schema'
6
7
import { Metadata } from 'next'
@@ -13,10 +14,11 @@ export async function generateMetadata(props: PageProps): Promise<Metadata | nul
13
14
try {
14
15
const params = await props . params
15
16
const { metadata } = await importPage ( params . mdxPath || [ ] , params . lang )
16
-
17
- // Check if this is the homepage
18
17
const isHomepage = ! params . mdxPath || params . mdxPath . length === 0
19
18
19
+ // Include the language prefix in the canonical path
20
+ const canonicalPath = `/${ params . lang } ${ params . mdxPath ? `/${ params . mdxPath . join ( '/' ) } ` : '' } `
21
+
20
22
const ogImage = {
21
23
url : isHomepage
22
24
? '/og/opengraph-image.png'
@@ -31,6 +33,9 @@ export async function generateMetadata(props: PageProps): Promise<Metadata | nul
31
33
openGraph : {
32
34
...metadata . openGraph ,
33
35
images : [ ogImage ]
36
+ } ,
37
+ alternates : {
38
+ canonical : `${ BASE_URL } ${ canonicalPath } `
34
39
}
35
40
}
36
41
} catch ( e ) {
You can’t perform that action at this time.
0 commit comments