forked from oaknational/Oak-Web-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSeo.tsx
75 lines (67 loc) · 1.75 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
import React, { FC } from "react";
import { NextSeo } from "next-seo";
import { useRouter } from "next/router";
import { SOCIAL_SHARING_IMAGE_URL } from "../../image-data";
import getBrowserConfig from "../getBrowserConfig";
export const DEFAULT_SEO_PROPS = {
title: getBrowserConfig("seoAppName"),
description: getBrowserConfig("seoAppDescription"),
};
export const BETA_SEO_PROPS = {
title: getBrowserConfig("seoAppName"),
description: getBrowserConfig("seoAppDescription"),
noIndex: true,
noFollow: true,
};
export type SeoProps = {
title: string;
description: string;
canonicalURL?: string;
noIndex?: boolean;
noFollow?: boolean;
imageUrl?: string;
};
/**
* Oak Seo component. A wrapper round NextSeo with sensible defaults.
* @see [seo.md](../../../docs/seo.md)
*/
const Seo: FC<SeoProps> = ({
title,
description,
imageUrl = SOCIAL_SHARING_IMAGE_URL,
noIndex = false,
noFollow = false,
canonicalURL,
}) => {
const router = useRouter();
// Trim trailing slashes
const formattedCanonicalURL = (
canonicalURL || `${getBrowserConfig("seoAppUrl")}${router.asPath}`
)?.replace(/\/$/, ""); //?
return (
<NextSeo
title={title}
description={description}
canonical={formattedCanonicalURL}
openGraph={{
title,
description,
url: `${getBrowserConfig("seoAppUrl")}${router.asPath}`,
images: [
{
url: imageUrl,
},
],
site_name: getBrowserConfig("seoAppName"),
}}
twitter={{
handle: getBrowserConfig("seoAppTwitterHandle"),
site: getBrowserConfig("seoAppTwitterHandle"),
cardType: "summary_large_image",
}}
noindex={noIndex}
nofollow={noFollow}
/>
);
};
export default Seo;