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 = 'A JavaScript library for building user interfaces' ;
12
15
@@ -16,6 +19,32 @@ type Props = {
16
19
canonicalUrl : string ,
17
20
} ;
18
21
22
+ // only provide alternate links to pages in languages where 95-100% of core content has been translated
23
+ // which is determined by status enum of 2
24
+ const completeLanguages = languages . filter ( language => {
25
+ return language . status == 2 ;
26
+ } ) ;
27
+
28
+ const alternatePages = canonicalUrl => {
29
+ return completeLanguages . map ( language => (
30
+ < link
31
+ key = { ( 'alt-' , language . code ) }
32
+ rel = "alternate"
33
+ hreflang = { language . code }
34
+ href = { canonicalUrl . replace (
35
+ urlRoot ,
36
+ `https://${
37
+ language . code === 'en' ? '' : `${ language . code } .`
38
+ } reactjs.org`,
39
+ ) }
40
+ />
41
+ ) ) ;
42
+ } ;
43
+
44
+ const defaultPage = canonicalUrl => {
45
+ return canonicalUrl . replace ( urlRoot , 'https://reactjs.org' ) ;
46
+ } ;
47
+
19
48
const TitleAndMetaTags = ( { title, ogDescription, canonicalUrl} : Props ) => {
20
49
return (
21
50
< Helmet title = { title } >
@@ -29,6 +58,14 @@ const TitleAndMetaTags = ({title, ogDescription, canonicalUrl}: Props) => {
29
58
/>
30
59
< meta property = "fb:app_id" content = "623268441017527" />
31
60
{ canonicalUrl && < link rel = "canonical" href = { canonicalUrl } /> }
61
+ { canonicalUrl && (
62
+ < link
63
+ rel = "alternate"
64
+ href = { defaultPage ( canonicalUrl ) }
65
+ hreflang = "x-default"
66
+ />
67
+ ) }
68
+ { canonicalUrl && alternatePages ( canonicalUrl ) }
32
69
</ Helmet >
33
70
) ;
34
71
} ;
0 commit comments