My objective: Add code to the Layout component so that the Meta title, description, and image are updated with the current page the user is on based on content provided in the frontmatter. For example if the user navigates to the about page, the meta should display the following:
<title>About | Website</title>
<meta content="This is the about page" name="description">
<link rel="canonical" href="www.website.com/about" />
<meta property="og:image" content="/images/about-meta.png" />
While on the about page the corresponding meta is as such:
---
title: About
description: This is the about page
meta_image: /images/about-meta.png
slug: about
---
What I'm doing now: I'm adding all that information in a Helmet tag to the individual templates and I have the title template setup in the layout, but it seems like there's got to be a better way to just automatically set the Helmet component in the layout to read that.
Layout.jsx
<Helmet
defaultTitle={siteMetadata.title}
titleTemplate={`%s | ${siteMetadata.title}`}
/>
templates/about.jsx
<Helmet title={frontmatter.title} >
<meta property="og:image" content={frontmatter.meta_image}/>
<link rel="canonical" href="{siteMetadata.siteUrl}/{frontmatter.slug}" />
</Helmet>
Gatsby has this guide on creating a SEO component, but it doesn't to include how that works from the page template and uses jargon to define jargon so it's not particularly useful to me as a react noob. I'm not quite understanding what PropTypes are or what they do.
What I'm trying: I'd like to add a static query within the layout that will detect the current page slug then fetch the markdownremark based on the current slug and dynamically fill in the meta data so I don't have to add a helmet tag per page template.