docs: add a canonical URL `<link>` example (#3473)

pull/3474/head
skirtle 6 months ago committed by GitHub
parent fcf828c2a7
commit 9510cd70c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -645,6 +645,23 @@ export default {
}
```
#### 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 }]]
}
}
}
```
### transformHtml
- Type: `(code: string, id: string, context: TransformContext) => Awaitable<string | void>`

Loading…
Cancel
Save