Skip to content

Commit

Permalink
fix: chore: address minor PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorinaPacurar committed Jul 28, 2023
1 parent f4de5a6 commit 1fac61f
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ function AlternateLangHeaders(): JSX.Element {
} = useDocusaurusContext();
const alternatePageUtils = useAlternatePageUtils();

const currentHtmlLang = localeConfigs[currentLocale]?.htmlLang;
const currentHtmlLang = localeConfigs[currentLocale]!.htmlLang;

// HTML lang is a BCP 47 tag, but the Open Graph protocol requires
// using underscores instead of dashes.
// See https://ogp.me/#optional
// See https://en.wikipedia.org/wiki/IETF_language_tag)
const bcp47ToLocale = (code: string): string => code.replace('-', '_');
const bcp47ToOpenGraphLocale = (code: string): string =>
code.replace('-', '_');

// 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/
Expand All @@ -60,16 +61,17 @@ function AlternateLangHeaders(): JSX.Element {
hrefLang="x-default"
/>

{currentHtmlLang && (
<meta property="og:locale" content={bcp47ToLocale(currentHtmlLang)} />
)}
<meta
property="og:locale"
content={bcp47ToOpenGraphLocale(currentHtmlLang)}
/>
{Object.values(localeConfigs)
.filter((config) => currentHtmlLang !== config.htmlLang)
.map((config) => (
<meta
key={`meta-og-${config.htmlLang}`}
property="og:locale:alternate"
content={bcp47ToLocale(config.htmlLang)}
content={bcp47ToOpenGraphLocale(config.htmlLang)}
/>
))}
</Head>
Expand Down

0 comments on commit 1fac61f

Please sign in to comment.