7
7
8
8
import Helmet from 'react-helmet' ;
9
9
import React from 'react' ;
10
+ import { urlRoot } from 'site-constants' ;
11
+ // $FlowFixMe This is a valid path
12
+ import languages from '../../../content/languages.yml' ;
10
13
11
14
const defaultDescription =
12
15
'Một thư viện JavaScript xây dựng giao diện người dùng' ;
@@ -17,6 +20,32 @@ type Props = {
17
20
canonicalUrl : string ,
18
21
} ;
19
22
23
+ // only provide alternate links to pages in languages where 95-100% of core content has been translated
24
+ // which is determined by status enum of 2
25
+ const completeLanguages = languages . filter ( language => {
26
+ return language . status == 2 ;
27
+ } ) ;
28
+
29
+ const alternatePages = canonicalUrl => {
30
+ return completeLanguages . map ( language => (
31
+ < link
32
+ key = { ( 'alt-' , language . code ) }
33
+ rel = "alternate"
34
+ hreflang = { language . code }
35
+ href = { canonicalUrl . replace (
36
+ urlRoot ,
37
+ `https://${
38
+ language . code === 'en' ? '' : `${ language . code } .`
39
+ } reactjs.org`,
40
+ ) }
41
+ />
42
+ ) ) ;
43
+ } ;
44
+
45
+ const defaultPage = canonicalUrl => {
46
+ return canonicalUrl . replace ( urlRoot , 'https://reactjs.org' ) ;
47
+ } ;
48
+
20
49
const TitleAndMetaTags = ( { title, ogDescription, canonicalUrl} : Props ) => {
21
50
return (
22
51
< Helmet title = { title } >
@@ -30,6 +59,14 @@ const TitleAndMetaTags = ({title, ogDescription, canonicalUrl}: Props) => {
30
59
/>
31
60
< meta property = "fb:app_id" content = "623268441017527" />
32
61
{ canonicalUrl && < link rel = "canonical" href = { canonicalUrl } /> }
62
+ { canonicalUrl && (
63
+ < link
64
+ rel = "alternate"
65
+ href = { defaultPage ( canonicalUrl ) }
66
+ hreflang = "x-default"
67
+ />
68
+ ) }
69
+ { canonicalUrl && alternatePages ( canonicalUrl ) }
33
70
</ Helmet >
34
71
) ;
35
72
} ;
0 commit comments