Created
October 8, 2022 23:45
-
-
Save benjifriedman/2885e110cb618d335d5f2b3847922310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//index.js | |
import React from "react" | |
import { Link } from "gatsby" | |
import Layout from "../components/layout" | |
import Seo from "../components/seo.js" | |
const IndexPage = () => { | |
return ( | |
<Layout> | |
<Seo title="Home" /> | |
//homepage content | |
</Layout> | |
) | |
} | |
export default IndexPage | |
//seo.js | |
import React from "react" | |
import { Helmet } from "react-helmet" | |
import { useStaticQuery, graphql } from "gatsby" | |
const Seo = ({ title }) => { | |
const data = useStaticQuery(graphql` | |
query { | |
site { | |
siteMetadata { | |
title | |
} | |
} | |
} | |
`) | |
return <Helmet title={`${title} | ${data.site.siteMetadata.title}`} /> | |
} | |
export default Seo |
Just reviewing this again... so every page needs to have an export const Head
now?
@benjifriedman If you'd like to add SEO / metadata to the <head />
in a page, then yes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, try this.
Any file that is exported from
src/pages
is considered a Page in Gatsby.Any Gatsby Page can export the
Head
API. The Head API receives data the same was as the Page does. E.g on thedata
prop.You can pass any data you want on to the
<Seo />
component, either by querying data using GraphQL which then becomes availbe on thedata
prop, or by "hard-coding" the props.The
<Seo />
component returns normal HTML<meta />
elements. You can see the available options for meta data using something like https://metatags.io/.