Skip to content

Commit 1fac61f

Browse files
fix: chore: address minor PR feedback
1 parent f4de5a6 commit 1fac61f

File tree

1 file changed

+8
-6
lines changed
  • packages/docusaurus-theme-classic/src/theme/SiteMetadata

1 file changed

+8
-6
lines changed

packages/docusaurus-theme-classic/src/theme/SiteMetadata/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ function AlternateLangHeaders(): JSX.Element {
2828
} = useDocusaurusContext();
2929
const alternatePageUtils = useAlternatePageUtils();
3030

31-
const currentHtmlLang = localeConfigs[currentLocale]?.htmlLang;
31+
const currentHtmlLang = localeConfigs[currentLocale]!.htmlLang;
3232

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

3940
// Note: it is fine to use both "x-default" and "en" to target the same url
4041
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
@@ -60,16 +61,17 @@ function AlternateLangHeaders(): JSX.Element {
6061
hrefLang="x-default"
6162
/>
6263

63-
{currentHtmlLang && (
64-
<meta property="og:locale" content={bcp47ToLocale(currentHtmlLang)} />
65-
)}
64+
<meta
65+
property="og:locale"
66+
content={bcp47ToOpenGraphLocale(currentHtmlLang)}
67+
/>
6668
{Object.values(localeConfigs)
6769
.filter((config) => currentHtmlLang !== config.htmlLang)
6870
.map((config) => (
6971
<meta
7072
key={`meta-og-${config.htmlLang}`}
7173
property="og:locale:alternate"
72-
content={bcp47ToLocale(config.htmlLang)}
74+
content={bcp47ToOpenGraphLocale(config.htmlLang)}
7375
/>
7476
))}
7577
</Head>

0 commit comments

Comments
 (0)