-
-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathseo.tsx
109 lines (100 loc) · 2.91 KB
/
seo.tsx
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
105
106
107
108
109
/**
* SEO component that queries for data with
* Gatsby's useStaticQuery React hook
*
* See: https://www.gatsbyjs.org/docs/use-static-query/
*/
import { graphql, useStaticQuery } from "gatsby";
import React, { FC } from "react";
import { Helmet } from "react-helmet";
export interface SEOProps {
readonly description?: string;
readonly imageUrl?: string;
readonly isArticle?: boolean;
readonly lang?: string;
readonly title: string;
}
export const SEO: FC<SEOProps> = ({
description,
imageUrl,
isArticle,
lang,
title,
}) => {
const { site, image } = useStaticQuery(
graphql`
query SEO {
site {
siteMetadata {
title
description
company
author
siteUrl
}
}
image: file(
relativePath: { eq: "chillicream-graphql-banner.png" }
sourceInstanceName: { eq: "images" }
) {
childImageSharp {
gatsbyImageData(layout: FIXED, width: 1200, quality: 100)
}
}
}
`
);
const metaSiteUrl = site.siteMetadata.siteUrl;
const metaAuthor = `@${site.siteMetadata.author}`;
const metaCompany = site.siteMetadata.company;
const metaDescription = description || site.siteMetadata.description;
const metaImageUrl = `${metaSiteUrl}${
imageUrl ?? image?.childImageSharp!.gatsbyImageData!.images.fallback.src
}`;
const metaType = isArticle ? "article" : "website";
return (
<Helmet
htmlAttributes={{
lang,
}}
>
<title>
{title} - {site.siteMetadata.title}
</title>
<meta name="description" content={metaDescription} />
<meta property="og:url" content={metaSiteUrl} />
<meta property="og:title" content={title} />
<meta property="og:description" content={metaDescription} />
<meta property="og:type" content={metaType} />
<meta property="og:image" content={metaImageUrl} />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content={title} />
<meta name="twitter:site" content={metaAuthor} />
<meta name="twitter:creator" content={metaAuthor} />
<meta name="twitter:image" content={metaImageUrl} />
{description && <meta name="twitter:description" content={description} />}
<script type="application/ld+json">
{JSON.stringify({
"@context": "https://schema.org/",
"@type": metaType,
"@id": metaSiteUrl,
headline: title,
description: metaDescription,
author: {
"@type": "Organization",
name: metaCompany,
contactPoint: {
"@type": "ContactPoint",
email: "mailto:contact@chillicream.com",
contactType: "Customer Support",
},
},
})}
</script>
</Helmet>
);
};
SEO.defaultProps = {
lang: `en`,
description: ``,
};