-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSEO.tsx
80 lines (74 loc) · 2.16 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
import Head from 'next/head';
import * as React from 'react';
export const SITE_NAME = 'GraphToy +';
export const SITE_TITLE =
"GraphToy + is a fork of IQ's graphtoy with extra features.";
export const SITE_DESCRIPTION =
"GraphToy + is a fork of IQ's graphtoy with extra features.";
export const SITE_IMAGE = '/static/site-image.jpg';
export const SITE_AUTHOR = 'Chris Sprance';
export type SEO = {
metaTitle: string;
metaDescription: string;
shareImage: string;
article: boolean;
};
export const defaultSeo: SEO = {
metaTitle: SITE_TITLE,
metaDescription: SITE_DESCRIPTION,
shareImage: SITE_IMAGE,
article: false,
};
const Seo: React.FC<{
metaTitle?: string;
metaDescription?: string;
shareImage?: string;
article: boolean;
}> = ({
metaTitle = defaultSeo.metaTitle,
metaDescription = defaultSeo.metaDescription,
shareImage = defaultSeo.shareImage,
article,
}) => {
const seoWithDefaults = {
metaTitle,
metaDescription,
shareImage,
article,
};
const fullSeo = {
...seoWithDefaults,
// Add title suffix
metaTitle: `${seoWithDefaults.metaTitle} | ${SITE_NAME}`,
// Get full image URL
shareImage: seoWithDefaults.shareImage,
};
return (
<Head>
{fullSeo.metaTitle && (
<>
<title>{fullSeo.metaTitle}</title>
<meta property="og:title" content={fullSeo.metaTitle} />
<meta name="twitter:title" content={fullSeo.metaTitle} />
</>
)}
{fullSeo.metaDescription && (
<>
<meta name="description" content={fullSeo.metaDescription} />
<meta property="og:description" content={fullSeo.metaDescription} />
<meta name="twitter:description" content={fullSeo.metaDescription} />
</>
)}
{fullSeo.shareImage && (
<>
<meta property="og:image" content={fullSeo.shareImage} />
<meta name="twitter:image" content={fullSeo.shareImage} />
<meta name="image" content={fullSeo.shareImage} />
</>
)}
{fullSeo.article && <meta property="og:type" content="article" />}
<meta name="twitter:card" content="summary_large_image" />
</Head>
);
};
export default Seo;