From da938cfa9e051485550577af541ac117e151022f Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 5 Aug 2020 16:46:40 -0700 Subject: [PATCH] feat: setup way to add tags to the current document --- src/components/Seo.js | 9 ++++++++- src/templates/GuideTemplate.js | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/Seo.js b/src/components/Seo.js index 1a9287717..dcd318910 100644 --- a/src/components/Seo.js +++ b/src/components/Seo.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { Helmet } from 'react-helmet'; import { useStaticQuery, graphql, withPrefix } from 'gatsby'; -function SEO({ description, lang, meta, title }) { +function SEO({ description, lang, meta, title, tags }) { const { site } = useStaticQuery( graphql` query { @@ -67,6 +67,12 @@ function SEO({ description, lang, meta, title }) { 'data-type': 'string', content: description, }, + ...(tags ?? []).map((tag) => ({ + name: 'tags', + class: 'swiftype', + 'data-type': 'string', + content: tag, + })), ]; // only add metadata if we have content @@ -100,6 +106,7 @@ SEO.propTypes = { lang: PropTypes.string, meta: PropTypes.arrayOf(PropTypes.object), title: PropTypes.string, + tags: PropTypes.arrayOf(PropTypes.string), }; export default SEO; diff --git a/src/templates/GuideTemplate.js b/src/templates/GuideTemplate.js index 39d8fcb65..e6a6dff7f 100644 --- a/src/templates/GuideTemplate.js +++ b/src/templates/GuideTemplate.js @@ -15,11 +15,11 @@ import SEO from '../components/Seo'; const GuideTemplate = ({ data }) => { const { mdx } = data; const { frontmatter, body } = mdx; - const { title, description, duration } = frontmatter; + const { title, description, duration, tags } = frontmatter; return ( <> - + {duration && ( @@ -64,6 +64,7 @@ export const pageQuery = graphql` path title description + tags } ...Resources_page