-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathSeo.js
66 lines (58 loc) · 1.9 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
import React from "react";
import PropTypes from "prop-types";
import Helmet from "react-helmet";
const absoluteUrl = path => `https://michelebertoli.github.io/css-in-js${path}`;
const seoImageURL = path => `https://michelebertoli.github.io${path}`;
const getMetaTags = ({ title, description, url, twitter, image }) => {
const metaTags = [
{ itemprop: "name", content: title },
{ itemprop: "description", content: description },
{ name: "description", content: description },
{ name: "twitter:title", content: title },
{ name: "twitter:description", content: description },
{ name: "twitter:creator", content: twitter },
{ name: "og:title", content: title },
{ name: "og:type", content: "website" },
{ name: "og:url", content: url },
{ name: "og:description", content: description },
{ name: "og:site_name", content: "CSS-in-JS" },
{ name: "og:locale", content: "en_EN" }
];
if (image) {
metaTags.push({ itemprop: "image", content: seoImageURL(image) });
metaTags.push({ name: "twitter:image:src", content: seoImageURL(image) });
metaTags.push({ name: "og:image", content: seoImageURL(image) });
metaTags.push({ name: "twitter:card", content: "summary_large_image" });
} else {
metaTags.push({ name: "twitter:card", content: "summary" });
}
return metaTags;
};
const getHtmlAttributes = () => {
let result = {
lang: "en"
};
return result;
};
const Seo = ({ title, description, path, twitter, image }) => (
<Helmet
htmlAttributes={getHtmlAttributes()}
title={title}
link={[{ rel: "canonical", href: absoluteUrl(path) }]}
meta={getMetaTags({
title,
description,
url: absoluteUrl(path),
twitter,
image
})}
/>
);
Seo.propTypes = {
title: PropTypes.string,
description: PropTypes.string,
path: PropTypes.string,
twitter: PropTypes.string,
image: PropTypes.string
};
export default Seo;