diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 6222cdbd530af3..ad88cf1e2618dc 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -331,5 +331,16 @@ export default defineConfig({ level: [2, 3], }, }, + transformPageData(pageData) { + const canonicalUrl = `${ogUrl}/${pageData.relativePath}` + .replace(/\/index\.md$/, '/') + .replace(/\.md$/, '/') + pageData.frontmatter.head ??= [] + pageData.frontmatter.head.unshift([ + 'link', + { rel: 'canonical', href: canonicalUrl }, + ]) + return pageData + }, buildEnd, })