This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
tribalwarshelp.com/src/common/Seo.js

120 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-01-04 17:12:05 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import { useStaticQuery, graphql } from 'gatsby';
2021-01-09 10:08:37 +00:00
import seoImg from '@images/seo.png';
2020-07-26 10:03:52 +00:00
function Seo({ description, lang, meta, title, pathname }) {
2020-07-26 10:03:52 +00:00
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
description
siteUrl
}
}
}
`
);
2020-07-26 10:03:52 +00:00
const metaDescription = description || site.siteMetadata.description;
2020-07-26 10:03:52 +00:00
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={`%s | ${site.siteMetadata.title}`}
meta={[
{
name: `description`,
content: metaDescription,
},
{
property: `og:site_name`,
content: site.siteMetadata.title,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescription,
},
{
property: `og:url`,
content: `${site.siteMetadata.siteUrl}${pathname}`,
},
{
property: `og:image`,
2021-01-09 10:08:37 +00:00
content: `${site.siteMetadata.siteUrl}${seoImg}`,
2020-07-26 10:03:52 +00:00
},
{
property: `og:image:width`,
content: `1280`,
},
{
property: `og:image:height`,
content: `640`,
},
{
property: `og:image`,
content: `website`,
},
{
property: `og:locale`,
content: `en`,
2020-07-26 10:03:52 +00:00
},
{
name: `twitter:card`,
content: `summary_large_image`,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
{
name: `twitter:url`,
content: `${site.siteMetadata.siteUrl}${pathname}`,
},
{
name: `twitter:image`,
2021-01-09 10:08:37 +00:00
content: `${site.siteMetadata.siteUrl}${seoImg}`,
2020-07-26 10:03:52 +00:00
},
{
name: `twitter:image:alt`,
content: site.siteMetadata.title,
},
].concat(meta)}
>
<link
rel="canonical"
content={`${site.siteMetadata.siteUrl}${pathname}`}
></link>
</Helmet>
);
2020-07-26 10:03:52 +00:00
}
Seo.defaultProps = {
2020-07-26 10:03:52 +00:00
lang: `en`,
meta: [],
description: ``,
};
2020-07-26 10:03:52 +00:00
Seo.propTypes = {
2020-07-26 10:03:52 +00:00
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
};
2020-07-26 10:03:52 +00:00
export default Seo;