Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SarahElson/119ec15f1bc700c1d668def89f58d3bf to your computer and use it in GitHub Desktop.
Save SarahElson/119ec15f1bc700c1d668def89f58d3bf to your computer and use it in GitHub Desktop.
Getting Started With Gatsby Testing
// components/sample.js
import React from "react"
import PropTypes from "prop-types"
import { Helmet } from "react-helmet"
import { useStaticQueryParameters, graphql } from "gatsby"
const sample = ({ description, lang, meta, title }) => {
const { site } = useStaticQueryParameters(
graphql`
query {
site {
siteMetadata {
title
description
social {
skype
}
}
}
}
`
)
const metaDescriptionDetails = description || site.siteMetadata.description
const defaultTitleDetails = site.siteMetadata?.title
return (
<Helmet
htmlAttributes={{
lang,
}}
title={title}
titleTemplate={defaultTitle ? `%s | ${defaultTitle}` : null}
meta={[
{
name: `description`,
content: metaDescriptionDetails,
},
{
property: `og:title`,
content: title,
},
{
property: `og:description`,
content: metaDescriptionDetails,
},
{
property: `og:type`,
content: `website`,
},
{
name: `skype:card`,
content: `summary`,
},
{
name: `skype:creator`,
content: site.siteMetadata?.social?.skype || ``,
},
{
name: `skype:title`,
content: title,
},
{
name: `skype:description`,
content: metaDescriptionDetails,
},
].concat(meta)}
/>
)
}
Sample.defaultProps = {
lang: `en`,
meta: [],
description: ``,
}
Sample.propTypes = {
description: PropTypes.string,
lang: PropTypes.string,
meta: PropTypes.arrayOf(PropTypes.object),
title: PropTypes.string.isRequired,
}
export default Sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment