Skip to content

Commit

Permalink
fix(robots): missing robots meta tag (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Golden authored Jun 2, 2021
1 parent ef771bf commit 30a0494
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/components/SEO.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ describe('SEO', () => {
}]);
});

it('should provide the robots', () => {
const component = shallow(
<SEO
description="Lorem ipsum sat delor."
keywords={['foo', 'bar']}
robots={['index', 'follow']}
siteUrl="https://example.com"
title="Lorem Ipsum"
canonical="https://example.com/index.html"
/>
);

const helmet = component.find('Helmet');
const { meta } = helmet.props();

const robots = meta.find((tag) => tag.name === 'robots');

expect(robots).toMatchObject({
name: 'robots', content: 'index,follow',
});
});

it('should render image tags correctly', () => {
const component = shallow(
<SEO
Expand Down
7 changes: 7 additions & 0 deletions src/components/SEO.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SEO = ({
titleTemplate,
canonical,
keywords,
robots,
openGraph,
twitterCard,
image,
Expand Down Expand Up @@ -66,6 +67,10 @@ const SEO = ({
meta.push({ name: 'keywords', content: keywords.join(',') });
}

if (robots.length > 0) {
meta.push({ name: 'robots', content: robots.join(',') });
}

return (
<Helmet
htmlAttributes={{
Expand All @@ -90,6 +95,7 @@ SEO.propTypes = {
openGraph: openGraphShape,
twitterCard: twitterCardShape,
keywords: PropTypes.arrayOf(PropTypes.string),
robots: PropTypes.arrayOf(PropTypes.string),
image: PropTypes.shape({
url: PropTypes.string,
secureUrl: PropTypes.string,
Expand All @@ -114,6 +120,7 @@ SEO.defaultProps = {
titleTemplate: '',
canonical: '',
keywords: [],
robots: [],
image: undefined,
video: undefined,
openGraph: undefined,
Expand Down

0 comments on commit 30a0494

Please sign in to comment.