|
1 | 1 | import { IGatsbyImageData } from 'gatsby-plugin-image' |
2 | 2 | import { useMemo } from 'react' |
3 | | -import { Helmet } from 'react-helmet' |
4 | 3 |
|
5 | 4 | import useSiteMeta from '../../queries/useSiteMeta' |
6 | 5 |
|
7 | | -import { buildMetadata, MetaProps, LinkProps } from './helper' |
| 6 | +import { buildMetadata } from './helper' |
8 | 7 |
|
9 | 8 | export interface IPaginatorPageInfo { |
10 | 9 | currentPage: number |
11 | 10 | nextPage?: string |
12 | 11 | previousPage?: string |
13 | 12 | } |
14 | 13 |
|
15 | | -interface ISEOProps { |
| 14 | +export interface ISEOProps { |
16 | 15 | title?: string |
17 | 16 | defaultMetaTitle?: boolean |
18 | | - skipTitleTemplate?: boolean |
19 | 17 | description?: string |
20 | 18 | keywords?: string |
21 | 19 | imageAlt?: string |
22 | 20 | image?: IGatsbyImageData | string |
23 | 21 | imageHeight?: number |
24 | 22 | imageWidth?: number |
25 | | - meta?: MetaProps[] |
26 | | - link?: LinkProps[] |
27 | 23 | canonicalUrl?: string |
28 | 24 | pathname?: string |
29 | 25 | pageInfo?: IPaginatorPageInfo |
30 | 26 | children?: React.ReactNode |
31 | 27 | } |
32 | 28 |
|
33 | | -const GATSBY_USERCENTRICS_SETTINGS_ID = |
34 | | - process.env.GATSBY_USERCENTRICS_SETTINGS_ID |
35 | | - |
36 | 29 | const SEO: React.FC<ISEOProps> = ({ |
37 | 30 | title, |
38 | 31 | defaultMetaTitle, |
39 | | - skipTitleTemplate, |
40 | 32 | description, |
41 | 33 | keywords, |
42 | 34 | image = '/social-share.png', |
43 | 35 | imageAlt = '', |
44 | 36 | imageHeight = 630, |
45 | 37 | imageWidth = 1200, |
46 | | - meta = [], |
47 | | - link = [], |
48 | 38 | canonicalUrl, |
49 | 39 | pathname, |
50 | 40 | pageInfo, |
@@ -84,63 +74,19 @@ const SEO: React.FC<ISEOProps> = ({ |
84 | 74 | imageHeight, |
85 | 75 | pathname |
86 | 76 | ]) |
87 | | - |
| 77 | + const canonical = canonicalUrl || fullUrl |
88 | 78 | return ( |
89 | | - /* @ts-expect-error react-helmet types incompatible with React types */ |
90 | | - <Helmet |
91 | | - htmlAttributes={{ |
92 | | - lang: 'en' |
93 | | - }} |
94 | | - defaultTitle={siteMeta.title} |
95 | | - title={pageTitle} |
96 | | - titleTemplate={ |
97 | | - skipTitleTemplate |
98 | | - ? '' |
99 | | - : siteMeta.titleTemplate || `%s | ${siteMeta.title}` |
100 | | - } |
101 | | - meta={[...prebuildMeta, ...meta]} |
102 | | - link={[ |
103 | | - ...(canonicalUrl |
104 | | - ? [ |
105 | | - { |
106 | | - rel: 'canonical', |
107 | | - href: canonicalUrl |
108 | | - } |
109 | | - ] |
110 | | - : pathname |
111 | | - ? [ |
112 | | - { |
113 | | - rel: 'canonical', |
114 | | - href: fullUrl |
115 | | - } |
116 | | - ] |
117 | | - : []), |
118 | | - ...link |
119 | | - ]} |
120 | | - > |
121 | | - {GATSBY_USERCENTRICS_SETTINGS_ID && ( |
122 | | - <script src="https://web.cmp.usercentrics.eu/modules/autoblocker.js" /> |
123 | | - )} |
124 | | - {GATSBY_USERCENTRICS_SETTINGS_ID && ( |
125 | | - <script |
126 | | - id="usercentrics-cmp" |
127 | | - src="https://web.cmp.usercentrics.eu/ui/loader.js" |
128 | | - data-settings-id={GATSBY_USERCENTRICS_SETTINGS_ID} |
129 | | - async |
130 | | - /> |
131 | | - )} |
132 | | - {siteMeta.plausibleSrc ? ( |
133 | | - <script |
134 | | - defer |
135 | | - data-domain={ |
136 | | - siteMeta.plausibleDomain || new URL(siteMeta.siteUrl).hostname |
137 | | - } |
138 | | - data-api={siteMeta.plausibleAPI || undefined} |
139 | | - src={siteMeta.plausibleSrc} |
140 | | - /> |
141 | | - ) : null} |
| 79 | + <> |
| 80 | + <html lang="en" /> |
| 81 | + {canonical && <link rel="canonical" href={canonical} />} |
| 82 | + <title> |
| 83 | + {pageTitle ? `${pageTitle} | ${siteMeta.title}` : siteMeta.title} |
| 84 | + </title> |
| 85 | + {prebuildMeta.map((m, i) => ( |
| 86 | + <meta key={i} {...m} /> |
| 87 | + ))} |
142 | 88 | {children} |
143 | | - </Helmet> |
| 89 | + </> |
144 | 90 | ) |
145 | 91 | } |
146 | 92 |
|
|
0 commit comments