|
|
|
@ -645,19 +645,20 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### Example: Adding a canonical URL `<link>`
|
|
|
|
|
#### Example: Adding a canonical URL `<link>`
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
export default {
|
|
|
|
|
transformHead({ page }) {
|
|
|
|
|
// Skip the 404 page
|
|
|
|
|
if (page !== '404.md') {
|
|
|
|
|
const canonicalUrl = `https://example.com/${page}`
|
|
|
|
|
.replace(/index\.md$/, '')
|
|
|
|
|
.replace(/\.md$/, '.html')
|
|
|
|
|
|
|
|
|
|
return [['link', { rel: 'canonical', href: canonicalUrl }]]
|
|
|
|
|
}
|
|
|
|
|
transformPageData(pageData) {
|
|
|
|
|
const canonicalUrl = `https://example.com/${pageData.relativePath}`
|
|
|
|
|
.replace(/index\.md$/, '')
|
|
|
|
|
.replace(/\.md$/, '.html')
|
|
|
|
|
|
|
|
|
|
pageData.frontmatter.head ??= []
|
|
|
|
|
pageData.frontmatter.head.push([
|
|
|
|
|
'link',
|
|
|
|
|
{ rel: 'canonical', href: canonicalUrl }
|
|
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|