-
Notifications
You must be signed in to change notification settings - Fork 30
/
SEO.js
104 lines (96 loc) · 3.01 KB
/
SEO.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react';
import { Helmet } from 'react-helmet';
import { StaticQuery, graphql } from 'gatsby';
import PropTypes from 'prop-types';
import SchemaOrg from './SchemaOrg';
const SEO = ({ postData, frontmatter = {}, postImage, isBlogPost }) => (
<StaticQuery
query={graphql`
{
site {
siteMetadata {
title
description
siteUrl
image
author {
name
}
organization {
name
url
logo
}
social {
twitter
fbAppID
}
}
}
}
`}
render={({ site: { siteMetadata: seo } }) => {
const postMeta =
frontmatter || postData.childMarkdownRemark.frontmatter || {};
const title = postMeta.title || seo.title;
const description = postMeta.description || seo.description;
const image = postImage ? `${seo.siteUrl}${postImage}` : seo.image;
const url = postMeta.slug
? `${seo.siteUrl}/${postMeta.slug}/`
: seo.siteUrl;
const datePublished = isBlogPost ? postMeta.datePublished : false;
return (
<React.Fragment>
<Helmet>
{/* General tags */}
<title>{title}</title>
<meta name="description" content={description} />
<meta name="image" content={image} />
<link rel="canonical" href={url} />
{/* OpenGraph tags */}
<meta property="og:url" content={url} />
{isBlogPost ? <meta property="og:type" content="article" /> : null}
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={image} />
<meta property="fb:app_id" content={seo.social.fbAppID} />
{/* Twitter Card tags */}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:creator" content={seo.social.twitter} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="twitter:image" content={image} />
</Helmet>
<SchemaOrg
isBlogPost={isBlogPost}
url={url}
title={title}
image={image}
description={description}
datePublished={datePublished}
siteUrl={seo.siteUrl}
author={seo.author}
organization={seo.organization}
defaultTitle={seo.title}
/>
</React.Fragment>
);
}}
/>
);
SEO.propTypes = {
isBlogPost: PropTypes.bool,
postData: PropTypes.shape({
childMarkdownRemark: PropTypes.shape({
frontmatter: PropTypes.any,
excerpt: PropTypes.any,
}),
}),
postImage: PropTypes.string,
};
SEO.defaultProps = {
isBlogPost: false,
postData: { childMarkdownRemark: {} },
postImage: null,
};
export default SEO;