dwysokinski.me/src/components/SEO.js

125 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-07-13 09:45:24 +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 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
}
}
}
`
)
const metaDescription = description || site.siteMetadata.description
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title ?? site.siteMetadata.title}
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>
)
}
SEO.defaultProps = {
lang: `pl`,
meta: [],
description: ``,
}
SEO.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
}
export default SEO