import React from 'react'; import PropTypes from 'prop-types'; import { Helmet } from 'react-helmet'; import { useLocation } from '@reach/router'; import { useStaticQuery, graphql } from 'gatsby'; // https://www.gatsbyjs.com/docs/add-seo-component/ const Head = ({ title, description, image }) => { const { pathname } = useLocation(); const { site } = useStaticQuery( graphql` query { site { siteMetadata { defaultTitle: title defaultDescription: description siteUrl defaultImage: image twitterUsername } } } `, ); const { defaultTitle, defaultDescription, siteUrl, defaultImage, twitterUsername, } = site.siteMetadata; const seo = { title: title || defaultTitle, description: description || defaultDescription, image: `${siteUrl}${image || defaultImage}`, url: `${siteUrl}${pathname}`, }; return ( ); }; export default Head; Head.propTypes = { title: PropTypes.string, description: PropTypes.string, image: PropTypes.string, }; Head.defaultProps = { title: null, description: null, image: null, };