dwysokinski.me/src/components/Seo.js

122 lines
2.7 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';
2020-07-13 09:45:24 +00:00
function Seo({ description, lang, meta, title, pathname }) {
const { site, thumbnail } = useStaticQuery(
2020-07-13 09:45:24 +00:00
graphql`
{
2020-07-13 09:45:24 +00:00
site {
siteMetadata {
title
description
siteUrl
}
}
thumbnail: file(base: { eq: "thumbnail.png" }) {
publicURL
}
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}${thumbnail.publicURL}`,
2020-07-13 09:45:24 +00:00
},
{
property: `og:image:width`,
content: `400`,
},
{
property: `og:image:height`,
content: `400`,
},
{
property: `og:image`,
content: `website`,
},
{
property: `og:locale`,
content: `en`,
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}${thumbnail.publicURL}`,
2020-07-13 09:45:24 +00:00
},
{
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}`}
2021-11-09 07:56:58 +00:00
/>
2020-07-13 09:45:24 +00:00
</Helmet>
2021-01-17 08:31:50 +00:00
);
2020-07-13 09:45:24 +00:00
}
Seo.defaultProps = {
2020-07-13 09:45:24 +00:00
lang: `pl`,
meta: [],
description: ``,
2021-01-17 08:31:50 +00:00
};
2020-07-13 09:45:24 +00:00
Seo.propTypes = {
2020-07-13 09:45:24 +00:00
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string,
2021-01-17 08:31:50 +00:00
};
2020-07-13 09:45:24 +00:00
export default Seo;