Skip to content

Commit

Permalink
A first cut implementation of meta tags for alternate languages
Browse files Browse the repository at this point in the history
  • Loading branch information
domyen committed Jun 14, 2018
1 parent e8b5377 commit 0b8f967
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/templates/chapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,22 +211,40 @@ export default ({
data: {
currentPage,
pages,
site: { siteMetadata: { title: siteTitle, toc, githubUrl, codeGithubUrl } },
site: { siteMetadata: { title: siteTitle, toc, githubUrl, codeGithubUrl, siteUrl } },
},
location,
}) => {
const entries = tocEntries(toc, pages);
const { frontmatter: { commit, title, description }, fields: { slug, chapter } } = currentPage;
const {
frontmatter: { commit, title, description },
fields: { slug, chapter, framework, language },
} = currentPage;
const githubFileUrl = `${githubUrl}/blob/master/content/${slug.replace(/\//g, '')}.md`;

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

// This is not optimized.
let altLangUrl;
if (language === 'es') {
altLangUrl = 'en';
} else if (language === 'en') {
altLangUrl = 'es';
}

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}`}
/>
</Helmet>
<Sidebar>
<Heading>Table of Contents</Heading>
<DocsList>
Expand Down Expand Up @@ -310,6 +328,8 @@ export const query = graphql`
fields {
slug
chapter
framework
language
}
}
site {
Expand All @@ -318,6 +338,7 @@ export const query = graphql`
toc
githubUrl
codeGithubUrl
siteUrl
}
}
pages: allMarkdownRemark(
Expand Down

0 comments on commit 0b8f967

Please sign in to comment.