Skip to content

Commit

Permalink
fix hreflang
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Feb 2, 2021
1 parent ffb2d29 commit 8fc9932
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/docusaurus-theme-classic/src/theme/LayoutHead/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function AlternateLangHeaders(): JSX.Element {
i18n: {defaultLocale, locales},
} = useDocusaurusContext();
const alternatePageUtils = useAlternatePageUtils();

// Note: it is fine to use both "x-default" and "en" to target the same url
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
return (
<Head>
{locales.map((locale) => (
Expand All @@ -36,9 +39,17 @@ function AlternateLangHeaders(): JSX.Element {
locale,
fullyQualified: true,
})}
hrefLang={locale === defaultLocale ? 'x-default' : locale}
hrefLang={locale}
/>
))}
<link
rel="alternate"
href={alternatePageUtils.createUrl({
locale: defaultLocale,
fullyQualified: true,
})}
hrefLang="x-default"
/>
</Head>
);
}
Expand Down

0 comments on commit 8fc9932

Please sign in to comment.