Skip to content

Commit 0b9f36d

Browse files
Add canonical link to page head
1 parent eaef852 commit 0b9f36d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

.vitepress/config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { defineConfig } from 'vitepress';
22
import NavDefault from './nav.json';
33
import Sidebar from './sidebar';
44

5+
const SITE_HOSTNAME = 'https://docs.zoolanders.com';
6+
57
// https://vitepress.dev/reference/site-config
68
export default defineConfig({
79
title: 'ZOOlanders',
@@ -18,7 +20,7 @@ export default defineConfig({
1820
],
1921
],
2022
sitemap: {
21-
hostname: 'https://docs.zoolanders.com',
23+
hostname: SITE_HOSTNAME,
2224
},
2325
themeConfig: {
2426
logo: '/zoolanders.svg',
@@ -78,6 +80,15 @@ export default defineConfig({
7880
head.push(['meta', { name: 'robots', content: 'noindex,follow' }]);
7981
}
8082

83+
// Add canonical link so Google has a user-selected canonical for every page
84+
head.push([
85+
'link',
86+
{
87+
rel: 'canonical',
88+
href: SITE_HOSTNAME + '/' + pageData.relativePath.replace(/(index)?\.md$/, ''),
89+
},
90+
]);
91+
8192
return head.length ? head : undefined;
8293
},
8394
async transformPageData(pageData) {

0 commit comments

Comments
 (0)