react-datocms 3.0.10 → 3.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Seo/types.js +0 -2
- package/dist/cjs/Seo/types.js.map +1 -1
- package/dist/cjs/StructuredText/index.js.map +1 -1
- package/dist/esm/Seo/types.d.ts +4 -4
- package/dist/esm/Seo/types.js +0 -2
- package/dist/esm/Seo/types.js.map +1 -1
- package/dist/esm/StructuredText/index.d.ts +3 -3
- package/dist/esm/StructuredText/index.js.map +1 -1
- package/dist/types/Seo/types.d.ts +4 -4
- package/dist/types/StructuredText/index.d.ts +3 -3
- package/package.json +3 -2
- package/src/Image/__tests__/__snapshots__/index.test.tsx.snap +948 -0
- package/src/Image/__tests__/index.test.tsx +62 -0
- package/src/Image/index.tsx +294 -0
- package/src/Seo/__tests__/__snapshots__/index.test.tsx.snap +249 -0
- package/src/Seo/__tests__/index.test.tsx +309 -0
- package/src/Seo/index.ts +4 -0
- package/src/Seo/remixUtils.ts +34 -0
- package/src/Seo/renderMetaTags.tsx +32 -0
- package/src/Seo/renderMetaTagsToString.tsx +21 -0
- package/src/Seo/types.tsx +53 -0
- package/src/StructuredText/__tests__/__snapshots__/index.test.tsx.snap +331 -0
- package/src/StructuredText/__tests__/index.test.tsx +271 -0
- package/src/StructuredText/index.tsx +244 -0
- package/src/index.ts +4 -0
- package/src/setupTests.ts +6 -0
- package/src/useQuerySubscription/index.ts +89 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { shallow } from "enzyme";
|
|
3
|
+
import { renderMetaTags, renderMetaTagsToString, toRemixMeta } from "..";
|
|
4
|
+
import { TitleMetaLinkTag } from "../types";
|
|
5
|
+
|
|
6
|
+
const metaTags: TitleMetaLinkTag[] = [
|
|
7
|
+
{
|
|
8
|
+
"content": "Remix CMS - The easiest way to manage content with Remix",
|
|
9
|
+
"attributes": null,
|
|
10
|
+
"tag": "title"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"content": null,
|
|
14
|
+
"attributes": {
|
|
15
|
+
"property": "og:title",
|
|
16
|
+
"content": "Remix CMS - The easiest way to manage content with Remix"
|
|
17
|
+
},
|
|
18
|
+
"tag": "meta"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"content": null,
|
|
22
|
+
"attributes": {
|
|
23
|
+
"name": "twitter:title",
|
|
24
|
+
"content": "Remix CMS - The easiest way to manage content with Remix"
|
|
25
|
+
},
|
|
26
|
+
"tag": "meta"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"content": null,
|
|
30
|
+
"attributes": {
|
|
31
|
+
"name": "description",
|
|
32
|
+
"content": "Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now."
|
|
33
|
+
},
|
|
34
|
+
"tag": "meta"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"content": null,
|
|
38
|
+
"attributes": {
|
|
39
|
+
"property": "og:description",
|
|
40
|
+
"content": "Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now."
|
|
41
|
+
},
|
|
42
|
+
"tag": "meta"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"content": null,
|
|
46
|
+
"attributes": {
|
|
47
|
+
"name": "twitter:description",
|
|
48
|
+
"content": "Remix makes building scalable and fast React apps simple, pair it with a CMS that shares the same intuitiveness. Start a new Remix + Dato project now."
|
|
49
|
+
},
|
|
50
|
+
"tag": "meta"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"content": null,
|
|
54
|
+
"attributes": {
|
|
55
|
+
"property": "og:image",
|
|
56
|
+
"content": "https://www.datocms-assets.com/205/1642515293-full-logo.svg?fit=max&fm=jpg&w=1000"
|
|
57
|
+
},
|
|
58
|
+
"tag": "meta"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"content": null,
|
|
62
|
+
"attributes": {
|
|
63
|
+
"property": "og:image:width",
|
|
64
|
+
"content": "746"
|
|
65
|
+
},
|
|
66
|
+
"tag": "meta"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"content": null,
|
|
70
|
+
"attributes": {
|
|
71
|
+
"property": "og:image:height",
|
|
72
|
+
"content": "186"
|
|
73
|
+
},
|
|
74
|
+
"tag": "meta"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"content": null,
|
|
78
|
+
"attributes": {
|
|
79
|
+
"name": "twitter:image",
|
|
80
|
+
"content": "https://www.datocms-assets.com/205/1642515293-full-logo.svg?fit=max&fm=jpg&w=1000"
|
|
81
|
+
},
|
|
82
|
+
"tag": "meta"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"content": null,
|
|
86
|
+
"attributes": {
|
|
87
|
+
"property": "og:locale",
|
|
88
|
+
"content": "en"
|
|
89
|
+
},
|
|
90
|
+
"tag": "meta"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"content": null,
|
|
94
|
+
"attributes": {
|
|
95
|
+
"property": "og:type",
|
|
96
|
+
"content": "article"
|
|
97
|
+
},
|
|
98
|
+
"tag": "meta"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"content": null,
|
|
102
|
+
"attributes": {
|
|
103
|
+
"property": "og:site_name",
|
|
104
|
+
"content": "DatoCMS"
|
|
105
|
+
},
|
|
106
|
+
"tag": "meta"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"content": null,
|
|
110
|
+
"attributes": {
|
|
111
|
+
"property": "article:modified_time",
|
|
112
|
+
"content": "2022-01-18T14:02:47Z"
|
|
113
|
+
},
|
|
114
|
+
"tag": "meta"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"content": null,
|
|
118
|
+
"attributes": {
|
|
119
|
+
"name": "twitter:card",
|
|
120
|
+
"content": "summary_large_image"
|
|
121
|
+
},
|
|
122
|
+
"tag": "meta"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"content": null,
|
|
126
|
+
"attributes": {
|
|
127
|
+
"name": "twitter:site",
|
|
128
|
+
"content": "@datocms"
|
|
129
|
+
},
|
|
130
|
+
"tag": "meta"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"attributes": {
|
|
134
|
+
"sizes": "16x16",
|
|
135
|
+
"type": "image/png",
|
|
136
|
+
"rel": "icon",
|
|
137
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=16&w=16"
|
|
138
|
+
},
|
|
139
|
+
"content": null,
|
|
140
|
+
"tag": "link"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"attributes": {
|
|
144
|
+
"sizes": "32x32",
|
|
145
|
+
"type": "image/png",
|
|
146
|
+
"rel": "icon",
|
|
147
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=32&w=32"
|
|
148
|
+
},
|
|
149
|
+
"content": null,
|
|
150
|
+
"tag": "link"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"attributes": {
|
|
154
|
+
"sizes": "96x96",
|
|
155
|
+
"type": "image/png",
|
|
156
|
+
"rel": "icon",
|
|
157
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=96&w=96"
|
|
158
|
+
},
|
|
159
|
+
"content": null,
|
|
160
|
+
"tag": "link"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"attributes": {
|
|
164
|
+
"sizes": "192x192",
|
|
165
|
+
"type": "image/png",
|
|
166
|
+
"rel": "icon",
|
|
167
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=192&w=192"
|
|
168
|
+
},
|
|
169
|
+
"content": null,
|
|
170
|
+
"tag": "link"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"attributes": {
|
|
174
|
+
"sizes": "57x57",
|
|
175
|
+
"rel": "apple-touch-icon",
|
|
176
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=57&w=57"
|
|
177
|
+
},
|
|
178
|
+
"content": null,
|
|
179
|
+
"tag": "link"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"attributes": {
|
|
183
|
+
"sizes": "60x60",
|
|
184
|
+
"rel": "apple-touch-icon",
|
|
185
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=60&w=60"
|
|
186
|
+
},
|
|
187
|
+
"content": null,
|
|
188
|
+
"tag": "link"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"attributes": {
|
|
192
|
+
"sizes": "72x72",
|
|
193
|
+
"rel": "apple-touch-icon",
|
|
194
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=72&w=72"
|
|
195
|
+
},
|
|
196
|
+
"content": null,
|
|
197
|
+
"tag": "link"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"attributes": {
|
|
201
|
+
"sizes": "76x76",
|
|
202
|
+
"rel": "apple-touch-icon",
|
|
203
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=76&w=76"
|
|
204
|
+
},
|
|
205
|
+
"content": null,
|
|
206
|
+
"tag": "link"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"attributes": {
|
|
210
|
+
"sizes": "114x114",
|
|
211
|
+
"rel": "apple-touch-icon",
|
|
212
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=114&w=114"
|
|
213
|
+
},
|
|
214
|
+
"content": null,
|
|
215
|
+
"tag": "link"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"attributes": {
|
|
219
|
+
"sizes": "120x120",
|
|
220
|
+
"rel": "apple-touch-icon",
|
|
221
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=120&w=120"
|
|
222
|
+
},
|
|
223
|
+
"content": null,
|
|
224
|
+
"tag": "link"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"attributes": {
|
|
228
|
+
"sizes": "144x144",
|
|
229
|
+
"rel": "apple-touch-icon",
|
|
230
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=144&w=144"
|
|
231
|
+
},
|
|
232
|
+
"content": null,
|
|
233
|
+
"tag": "link"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"attributes": {
|
|
237
|
+
"sizes": "152x152",
|
|
238
|
+
"rel": "apple-touch-icon",
|
|
239
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=152&w=152"
|
|
240
|
+
},
|
|
241
|
+
"content": null,
|
|
242
|
+
"tag": "link"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"attributes": {
|
|
246
|
+
"sizes": "180x180",
|
|
247
|
+
"rel": "apple-touch-icon",
|
|
248
|
+
"href": "https://www.datocms-assets.com/205/1525789775-dato.png?h=180&w=180"
|
|
249
|
+
},
|
|
250
|
+
"content": null,
|
|
251
|
+
"tag": "link"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"attributes": {
|
|
255
|
+
"name": "msapplication-square70x70logo",
|
|
256
|
+
"content": "https://www.datocms-assets.com/205/1525789775-dato.png?h=70&w=70"
|
|
257
|
+
},
|
|
258
|
+
"content": null,
|
|
259
|
+
"tag": "meta"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"attributes": {
|
|
263
|
+
"name": "msapplication-square150x150logo",
|
|
264
|
+
"content": "https://www.datocms-assets.com/205/1525789775-dato.png?h=150&w=150"
|
|
265
|
+
},
|
|
266
|
+
"content": null,
|
|
267
|
+
"tag": "meta"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"attributes": {
|
|
271
|
+
"name": "msapplication-square310x310logo",
|
|
272
|
+
"content": "https://www.datocms-assets.com/205/1525789775-dato.png?h=310&w=310"
|
|
273
|
+
},
|
|
274
|
+
"content": null,
|
|
275
|
+
"tag": "meta"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"attributes": {
|
|
279
|
+
"name": "msapplication-square310x150logo",
|
|
280
|
+
"content": "https://www.datocms-assets.com/205/1525789775-dato.png?h=150&w=310"
|
|
281
|
+
},
|
|
282
|
+
"content": null,
|
|
283
|
+
"tag": "meta"
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
describe("renderMetaTags", () => {
|
|
288
|
+
it("generates an array of meta tags", () => {
|
|
289
|
+
const wrapper = shallow(
|
|
290
|
+
<head>
|
|
291
|
+
{renderMetaTags(metaTags)}
|
|
292
|
+
</head>
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
expect(wrapper).toMatchSnapshot();
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("renderMetaTagsToString", () => {
|
|
300
|
+
it("generates an array of meta tags", () => {
|
|
301
|
+
expect(renderMetaTagsToString(metaTags)).toMatchSnapshot();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("toRemixMeta", () => {
|
|
306
|
+
it("generates a meta descriptor", () => {
|
|
307
|
+
expect(toRemixMeta(metaTags)).toMatchSnapshot();
|
|
308
|
+
});
|
|
309
|
+
});
|
package/src/Seo/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TitleMetaLinkTag } from './types';
|
|
2
|
+
|
|
3
|
+
interface RemixHtmlMetaDescriptor {
|
|
4
|
+
[name: string]: string | string[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function toRemixMeta(
|
|
8
|
+
metaTags: null | TitleMetaLinkTag[],
|
|
9
|
+
): RemixHtmlMetaDescriptor {
|
|
10
|
+
if (!metaTags) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return metaTags.reduce((acc, tag) => {
|
|
15
|
+
if (tag.tag === 'title') {
|
|
16
|
+
return tag.content ? { ...acc, title: tag.content } : acc;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (tag.tag === 'link') {
|
|
20
|
+
return acc;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!tag.attributes) {
|
|
24
|
+
return acc;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...acc,
|
|
29
|
+
['property' in tag.attributes
|
|
30
|
+
? tag.attributes.property
|
|
31
|
+
: tag.attributes.name]: tag.attributes.content,
|
|
32
|
+
};
|
|
33
|
+
}, {} as RemixHtmlMetaDescriptor);
|
|
34
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TitleMetaLinkTag } from './types';
|
|
3
|
+
|
|
4
|
+
export function renderMetaTags(data: TitleMetaLinkTag[]): JSX.Element[] {
|
|
5
|
+
return data.map(({ tag, attributes, content }) => {
|
|
6
|
+
let key: string[] = [tag];
|
|
7
|
+
|
|
8
|
+
if (attributes && 'property' in attributes) {
|
|
9
|
+
key.push(attributes.property);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (attributes && 'name' in attributes) {
|
|
13
|
+
key.push(attributes.name);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (attributes && 'rel' in attributes) {
|
|
17
|
+
key.push(attributes.rel);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (attributes && 'sizes' in attributes) {
|
|
21
|
+
key.push(attributes.sizes);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const Tag = tag as 'meta' | 'title' | 'link';
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Tag key={key.join('-')} {...attributes}>
|
|
28
|
+
{content}
|
|
29
|
+
</Tag>
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TitleMetaLinkTag } from "./types";
|
|
2
|
+
|
|
3
|
+
export function renderMetaTagsToString(data: TitleMetaLinkTag[]): string {
|
|
4
|
+
return data
|
|
5
|
+
.map((tag) => {
|
|
6
|
+
if (tag.tag === 'title') {
|
|
7
|
+
return `<title>${tag.content}</title>`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const serializedAttrs = [];
|
|
11
|
+
|
|
12
|
+
for (const key in tag.attributes) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(tag.attributes, key)) {
|
|
14
|
+
serializedAttrs.push(`${key}="${(tag.attributes as any)[key]}"`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `<${tag.tag} ${serializedAttrs.join(' ')} />`;
|
|
19
|
+
})
|
|
20
|
+
.join('\n');
|
|
21
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface TitleMetaLinkTag {
|
|
2
|
+
/** the tag for the meta information */
|
|
3
|
+
tag: string;
|
|
4
|
+
/** the inner content of the meta tag */
|
|
5
|
+
content: string | null | undefined;
|
|
6
|
+
/** the HTML attributes to attach to the meta tag */
|
|
7
|
+
attributes: Record<string, string> | null | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SeoTitleTag {
|
|
11
|
+
tag: 'title';
|
|
12
|
+
content: string | null;
|
|
13
|
+
attributes?: null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RegularMetaAttributes {
|
|
17
|
+
name: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface OgMetaAttributes {
|
|
22
|
+
property: string;
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SeoMetaTag {
|
|
27
|
+
tag: 'meta';
|
|
28
|
+
content?: null;
|
|
29
|
+
attributes: RegularMetaAttributes | OgMetaAttributes;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FaviconAttributes {
|
|
33
|
+
sizes: string;
|
|
34
|
+
type: string;
|
|
35
|
+
rel: string;
|
|
36
|
+
href: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface AppleTouchIconAttributes {
|
|
40
|
+
sizes: string;
|
|
41
|
+
rel: 'apple-touch-icon';
|
|
42
|
+
href: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SeoLinkTag {
|
|
46
|
+
tag: 'link';
|
|
47
|
+
content?: null;
|
|
48
|
+
attributes: FaviconAttributes | AppleTouchIconAttributes;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type SeoTag = SeoTitleTag | SeoMetaTag;
|
|
52
|
+
export type FaviconTag = SeoMetaTag | SeoLinkTag;
|
|
53
|
+
export type SeoOrFaviconTag = SeoTag | FaviconTag;
|