fesite/src/components/seo.tsx

89 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-01-23 12:06:17 +00:00
/**
* SEO component that queries for data with
* Gatsby's useStaticQuery React hook
*
* See: https://www.gatsbyjs.org/docs/use-static-query/
*/
2020-01-23 15:10:37 +00:00
import React from "react";
import PropTypes from "prop-types";
import Helmet from "react-helmet";
import { useStaticQuery, graphql } from "gatsby";
2020-01-23 12:06:17 +00:00
function SEO({ description, lang, meta, title }) {
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
description
author
}
}
}
`
2020-01-23 15:10:37 +00:00
);
2020-01-23 12:06:17 +00:00
2020-01-23 15:10:37 +00:00
const metaDescription = description || site.siteMetadata.description;
2020-01-23 12:06:17 +00:00
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={[
{
name: `description`,
content: metaDescription,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:type`,
content: `website`,
},
{
name: `twitter:card`,
content: `summary`,
},
{
name: `twitter:creator`,
content: site.siteMetadata.author,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
].concat(meta)}
/>
2020-01-23 15:10:37 +00:00
);
2020-01-23 12:06:17 +00:00
}
SEO.defaultProps = {
lang: `en`,
meta: [],
description: ``,
2020-01-23 15:10:37 +00:00
};
2020-01-23 12:06:17 +00:00
SEO.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
2020-01-23 15:10:37 +00:00
};
2020-01-23 12:06:17 +00:00
2020-01-23 15:10:37 +00:00
export default SEO;