Skip to content

Commit

Permalink
Wire up language alt links
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Jun 15, 2018
1 parent 7f3629b commit 6e527a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
'conclusion',
'contribute',
],
languages: ['en', 'es'],
defaultTranslation: 'react/en',
siteUrl: 'https://learnstorybook.com',
githubUrl: 'https://github.com/hichroma/learnstorybook.com',
Expand Down
25 changes: 11 additions & 14 deletions src/templates/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default ({
data: {
currentPage,
pages,
site: { siteMetadata: { title: siteTitle, toc, githubUrl, codeGithubUrl, siteUrl } },
site: { siteMetadata: { title: siteTitle, toc, languages, githubUrl, codeGithubUrl, siteUrl } },
},
location,
}) => {
Expand All @@ -224,26 +224,22 @@ export default ({

const nextEntry = entries[toc.indexOf(chapter) + 1];

// This is not optimized.
let altLangUrl;
if (language === 'es') {
altLangUrl = 'en';
} else if (language === 'en') {
altLangUrl = 'es';
}
const otherLanguages = languages.filter(l => l !== language);

return (
<DocsWrapper>
<Helmet
title={`${title} | ${siteTitle}`}
meta={[{ name: 'description', content: description }]}
>
<link
// TODO: map every language supported and generate an alt URL for each
rel="alternate"
hrefLang={altLangUrl}
href={`${siteUrl}/${framework}/${altLangUrl}/${chapter}`}
/>
{otherLanguages.map(otherLanguage => (
<link
key={otherLanguage}
rel="alternate"
hrefLang={otherLanguage}
href={`/${framework}/${otherLanguage}/${chapter}`}
/>
))}
</Helmet>
<Sidebar>
<Heading>Table of Contents</Heading>
Expand Down Expand Up @@ -336,6 +332,7 @@ export const query = graphql`
siteMetadata {
title
toc
languages
githubUrl
codeGithubUrl
siteUrl
Expand Down

0 comments on commit 6e527a9

Please sign in to comment.