File tree 1 file changed +11
-10
lines changed
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -645,19 +645,20 @@ export default {
645
645
}
646
646
```
647
647
648
- #### Example: Adding a canonical URL ` <link> `
648
+ #### Example: Adding a canonical URL ` <link> `
649
649
650
650
``` ts
651
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
- }
652
+ transformPageData(pageData ) {
653
+ const canonicalUrl = ` https://example.com/${pageData .relativePath } `
654
+ .replace (/ index\. md$ / , ' ' )
655
+ .replace (/ \. md$ / , ' .html' )
656
+
657
+ pageData .frontmatter .head ?? = []
658
+ pageData .frontmatter .head .push ([
659
+ ' link' ,
660
+ { rel: ' canonical' , href: canonicalUrl }
661
+ ])
661
662
}
662
663
}
663
664
```
You can’t perform that action at this time.
0 commit comments