dwysokinski.me/src/components/SEO.js

125 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-01-17 08:31:50 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { Helmet } from 'react-helmet';
import { useStaticQuery, graphql } from 'gatsby';
import ogThumbnail from '@images/og_thumbnail.png';
2020-07-13 09:45:24 +00:00
2020-07-13 17:04:46 +00:00
function SEO({ description, lang, meta, title, pathname }) {
2020-07-13 09:45:24 +00:00
const { site } = useStaticQuery(
graphql`
query {
site {
siteMetadata {
title
description
siteUrl
authorTwitter
2020-07-13 09:45:24 +00:00
}
}
}
`
2021-01-17 08:31:50 +00:00
);
2020-07-13 09:45:24 +00:00
2021-01-17 08:31:50 +00:00
const metaDescription = description || site.siteMetadata.description;
2020-07-13 09:45:24 +00:00
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title ?? site.siteMetadata.title}
2021-01-17 08:31:50 +00:00
titleTemplate={title ? `%s | ${site.siteMetadata.title}` : '%s'}
2020-07-13 09:45:24 +00:00
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`,
2020-07-13 17:04:46 +00:00
content: `${site.siteMetadata.siteUrl}${pathname}`,
2020-07-13 09:45:24 +00:00
},
{
property: `og:image`,
content: `${site.siteMetadata.siteUrl}${ogThumbnail}`,
},
{
property: `og:image:width`,
content: `400`,
},
{
property: `og:image:height`,
content: `400`,
},
{
property: `og:image`,
content: `website`,
},
{
property: `og:locale`,
content: `pl`,
},
{
name: `twitter:creator`,
content: site.siteMetadata.authorTwitter,
2020-07-13 09:45:24 +00:00
},
{
name: `twitter:card`,
content: `summary_large_image`,
},
{
name: `twitter:title`,
content: title,
},
{
name: `twitter:description`,
content: metaDescription,
},
{
name: `twitter:url`,
2020-07-13 17:04:46 +00:00
content: `${site.siteMetadata.siteUrl}${pathname}`,
2020-07-13 09:45:24 +00:00
},
{
name: `twitter:image`,
content: `${site.siteMetadata.siteUrl}${ogThumbnail}`,
},
{
name: `twitter:image:alt`,
content: site.siteMetadata.title,
},
].concat(meta)}
>
<link
rel="canonical"
2020-07-13 17:04:46 +00:00
content={`${site.siteMetadata.siteUrl}${pathname}`}
2020-07-13 09:45:24 +00:00
></link>
</Helmet>
2021-01-17 08:31:50 +00:00
);
2020-07-13 09:45:24 +00:00
}
SEO.defaultProps = {
lang: `pl`,
meta: [],
description: ``,
2021-01-17 08:31:50 +00:00
};
2020-07-13 09:45:24 +00:00
SEO.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
2021-01-17 08:31:50 +00:00
};
2020-07-13 09:45:24 +00:00
2021-01-17 08:31:50 +00:00
export default SEO;