-
Notifications
You must be signed in to change notification settings - Fork 48
/
SEO.jsx
96 lines (92 loc) · 2.73 KB
/
SEO.jsx
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
import React, { Component } from "react";
import Helmet from "react-helmet";
import config from "../../../data/SiteConfig";
// eslint-disable-next-line react/prefer-stateless-function
class SEO extends Component {
render() {
const { postNode, postPath, postSEO } = this.props;
let title;
let description;
let image;
let postURL;
if (postSEO) {
const postMeta = postNode.frontmatter;
title = postMeta.title;
description = postMeta.description
? postMeta.description
: postNode.excerpt;
image = postMeta.cover || config.siteLogo;
postURL = config.siteUrl + config.pathPrefix + postPath;
} else {
title = config.siteTitle;
description = config.siteDescription;
image = config.siteLogo;
}
const realPrefix = config.pathPrefix === "/" ? "" : config.pathPrefix;
image = config.siteUrl + realPrefix + image;
const blogURL = config.siteUrl + config.pathPrefix;
const schemaOrgJSONLD = [
{
"@context": "http://schema.org",
"@type": "WebSite",
url: blogURL,
name: title,
alternateName: config.siteTitleAlt ? config.siteTitleAlt : ""
}
];
if (postSEO) {
schemaOrgJSONLD.push([
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
itemListElement: [
{
"@type": "ListItem",
position: 1,
item: {
"@id": postURL,
name: title,
image
}
}
]
},
{
"@context": "http://schema.org",
"@type": "BlogPosting",
url: blogURL,
name: title,
alternateName: config.siteTitleAlt ? config.siteTitleAlt : "",
headline: title,
image: {
"@type": "ImageObject",
url: image
},
description
}
]);
}
return (
<Helmet>
{/* General tags */}
<meta name="description" content={description} />
<meta name="image" content={image} />
{/* Schema.org tags */}
<script type="application/ld+json">
{JSON.stringify(schemaOrgJSONLD)}
</script>
{/* OpenGraph tags */}
<meta property="og:url" content={postSEO ? postURL : blogURL} />
{postSEO ? <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={config.siteFBAppID ? config.siteFBAppID : ""}
/>
</Helmet>
);
}
}
export default SEO;