Skip to content

Commit 9510cd7

Browse files
docs: add a canonical URL <link> example (#3473)
1 parent fcf828c commit 9510cd7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/reference/site-config.md

+17
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,23 @@ export default {
645645
}
646646
```
647647

648+
#### Example: Adding a canonical URL `<link>`
649+
650+
```ts
651+
export default {
652+
transformHead({ page }) {
653+
// Skip the 404 page
654+
if (page !== '404.md') {
655+
const canonicalUrl = `https://example.com/${page}`
656+
.replace(/index\.md$/, '')
657+
.replace(/\.md$/, '.html')
658+
659+
return [['link', { rel: 'canonical', href: canonicalUrl }]]
660+
}
661+
}
662+
}
663+
```
664+
648665
### transformHtml
649666

650667
- Type: `(code: string, id: string, context: TransformContext) => Awaitable<string | void>`

0 commit comments

Comments
 (0)