Skip to content

Commit

Permalink
feat: setup way to add tags to the current document
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 5, 2020
1 parent 384008d commit da938cf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/components/Seo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
5 changes: 3 additions & 2 deletions src/templates/GuideTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<SEO title={title} description={description} />
<SEO title={title} description={description} tags={tags} />
<PageLayout type={PageLayout.TYPE.RELATED_CONTENT}>
<PageLayout.Header title={title}>
{duration && (
Expand Down Expand Up @@ -64,6 +64,7 @@ export const pageQuery = graphql`
path
title
description
tags
}
...Resources_page
Expand Down

0 comments on commit da938cf

Please sign in to comment.