Skip to content

Commit cc388d9

Browse files
authored
docs: add canonical url in head (#15984)
1 parent a839c14 commit cc388d9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/.vitepress/config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,16 @@ export default defineConfig({
331331
level: [2, 3],
332332
},
333333
},
334+
transformPageData(pageData) {
335+
const canonicalUrl = `${ogUrl}/${pageData.relativePath}`
336+
.replace(/\/index\.md$/, '/')
337+
.replace(/\.md$/, '/')
338+
pageData.frontmatter.head ??= []
339+
pageData.frontmatter.head.unshift([
340+
'link',
341+
{ rel: 'canonical', href: canonicalUrl },
342+
])
343+
return pageData
344+
},
334345
buildEnd,
335346
})

0 commit comments

Comments
 (0)