File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ import Head from 'next/head'
22import { useRouter } from 'next/router'
33import { useIntl } from 'react-intl'
44
5+ const BASE_URL = 'https://explorer.ooni.org'
6+ const LOCALES = JSON . parse ( process . env . LOCALES || '["en"]' )
7+
58const Header = ( ) => {
69 const { asPath, locale, defaultLocale } = useRouter ( )
710
11+ const path = asPath . split ( '?' ) [ 0 ]
812 const lang = locale === defaultLocale ? '' : `/${ locale } `
9- const canonical = `https://explorer.ooni.org ${ lang } ${ asPath . split ( '?' ) [ 0 ] } `
13+ const canonical = `${ BASE_URL } ${ lang } ${ path } `
1014
1115 const intl = useIntl ( )
1216 const description = intl . formatMessage ( { id : 'Home.Meta.Description' } )
@@ -50,6 +54,19 @@ const Header = () => {
5054 < link rel = "canonical" key = "canonical" href = { canonical } />
5155 < meta property = "og:url" key = "og:url" content = { canonical } />
5256
57+ { LOCALES . map ( ( loc ) => {
58+ const prefix = loc === defaultLocale ? '' : `/${ loc } `
59+ return (
60+ < link
61+ key = { `hreflang-${ loc } ` }
62+ rel = "alternate"
63+ hrefLang = { loc }
64+ href = { `${ BASE_URL } ${ prefix } ${ path } ` }
65+ />
66+ )
67+ } ) }
68+ < link rel = "alternate" hrefLang = "x-default" href = { `${ BASE_URL } ${ path } ` } />
69+
5370 < meta name = "twitter:card" content = "summary_large_image" />
5471 < meta key = "twitter:title" name = "twitter:title" content = "OONI Explorer" />
5572 < meta name = "twitter:site" content = "@openobservatory" />
You can’t perform that action at this time.
0 commit comments