|
| 1 | +import React from "react" |
| 2 | +import PropTypes from "prop-types" |
| 3 | +import { Helmet } from "react-helmet" |
| 4 | +// import { useLocation } from "@reach/router" |
| 5 | +import { useStaticQuery, graphql } from "gatsby" |
| 6 | + |
| 7 | +const SEO = ({ title, description, image }) => { |
| 8 | + // const { pathname } = useLocation() |
| 9 | + const { site } = useStaticQuery(query) |
| 10 | + |
| 11 | + const { |
| 12 | + defaultTitle, |
| 13 | + defaultDescription, |
| 14 | + siteUrl, |
| 15 | + defaultImage, |
| 16 | + } = site.siteMetadata |
| 17 | + |
| 18 | + const seo = { |
| 19 | + title: title || defaultTitle, |
| 20 | + description: description || defaultDescription, |
| 21 | + // image: `${siteUrl}${image || defaultImage}`, |
| 22 | + // url: `${siteUrl}${pathname}`, |
| 23 | + } |
| 24 | + |
| 25 | + return ( |
| 26 | + <Helmet title={seo.title}> |
| 27 | + <meta name="description" content={seo.description} /> |
| 28 | + <meta name="image" content={seo.image} /> |
| 29 | + <meta name="author" content={seo.author} /> |
| 30 | + |
| 31 | + {seo.url && <meta property="og:url" content={seo.url} />} |
| 32 | + |
| 33 | + {seo.title && <meta property="og:title" content={seo.title} />} |
| 34 | + |
| 35 | + {seo.description && ( |
| 36 | + <meta property="og:description" content={seo.description} /> |
| 37 | + )} |
| 38 | + |
| 39 | + {/* {seo.image && <meta property="og:image" content={seo.image} />} */} |
| 40 | + {/* {(article ? true : null) && <meta property="og:type" content="article" />} */} |
| 41 | + </Helmet> |
| 42 | + ) |
| 43 | +} |
| 44 | + |
| 45 | +export default SEO |
| 46 | + |
| 47 | +SEO.propTypes = { |
| 48 | + title: PropTypes.string, |
| 49 | + description: PropTypes.string, |
| 50 | + image: PropTypes.string, |
| 51 | + article: PropTypes.bool, |
| 52 | +} |
| 53 | + |
| 54 | +SEO.defaultProps = { |
| 55 | + title: null, |
| 56 | + description: null, |
| 57 | + image: null, |
| 58 | + article: false, |
| 59 | +} |
| 60 | + |
| 61 | +const query = graphql` |
| 62 | + query SEO { |
| 63 | + site { |
| 64 | + siteMetadata { |
| 65 | + defaultTitle: title |
| 66 | + defaultDescription: description |
| 67 | + siteUrl: url |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | +` |
0 commit comments