@@ -28,13 +28,14 @@ function AlternateLangHeaders(): JSX.Element {
28
28
} = useDocusaurusContext ( ) ;
29
29
const alternatePageUtils = useAlternatePageUtils ( ) ;
30
30
31
- const currentHtmlLang = localeConfigs [ currentLocale ] ? .htmlLang ;
31
+ const currentHtmlLang = localeConfigs [ currentLocale ] ! . htmlLang ;
32
32
33
33
// HTML lang is a BCP 47 tag, but the Open Graph protocol requires
34
34
// using underscores instead of dashes.
35
35
// See https://ogp.me/#optional
36
36
// 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 ( '-' , '_' ) ;
38
39
39
40
// Note: it is fine to use both "x-default" and "en" to target the same url
40
41
// See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
@@ -60,16 +61,17 @@ function AlternateLangHeaders(): JSX.Element {
60
61
hrefLang = "x-default"
61
62
/>
62
63
63
- { currentHtmlLang && (
64
- < meta property = "og:locale" content = { bcp47ToLocale ( currentHtmlLang ) } />
65
- ) }
64
+ < meta
65
+ property = "og:locale"
66
+ content = { bcp47ToOpenGraphLocale ( currentHtmlLang ) }
67
+ />
66
68
{ Object . values ( localeConfigs )
67
69
. filter ( ( config ) => currentHtmlLang !== config . htmlLang )
68
70
. map ( ( config ) => (
69
71
< meta
70
72
key = { `meta-og-${ config . htmlLang } ` }
71
73
property = "og:locale:alternate"
72
- content = { bcp47ToLocale ( config . htmlLang ) }
74
+ content = { bcp47ToOpenGraphLocale ( config . htmlLang ) }
73
75
/>
74
76
) ) }
75
77
</ Head >
0 commit comments