File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import SiteMetadata from "@theme-original/SiteMetadata" ;
3+ import type SiteMetadataType from "@theme/SiteMetadata" ;
4+ import type { WrapperProps } from "@docusaurus/types" ;
5+ import Head from "@docusaurus/Head" ;
6+ import useDocusaurusContext from "@docusaurus/useDocusaurusContext" ;
7+ import { useLocation } from "react-router" ;
8+
9+ type Props = WrapperProps < typeof SiteMetadataType > ;
10+
11+ export default function SiteMetadataWrapper ( props : Props ) : JSX . Element {
12+ const location = useLocation ( ) ;
13+ const { siteConfig } = useDocusaurusContext ( ) ;
14+
15+ let canonical = new URL ( location . pathname , siteConfig . url ) . href ;
16+ // sidebar.js generates alternate pages that end in -1, -2, .etc
17+ // this canonical href fix will prevent search engines from indexing those pages as unique and instead dedupe
18+ if ( canonical . substring ( canonical . length - 2 ) . match ( / - [ 0 - 9 ] / ) ) {
19+ canonical = canonical . substring ( 0 , canonical . length - 2 ) ;
20+ }
21+
22+ return (
23+ < >
24+ < SiteMetadata { ...props } />
25+ < Head >
26+ < link rel = "canonical" href = { canonical } > </ link >
27+ </ Head >
28+ </ >
29+ ) ;
30+ }
You can’t perform that action at this time.
0 commit comments