@quintype/seo 1.41.4 → 1.42.0-watermark-feature.0
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/index.cjs.js +30 -12
- package/package.json +1 -1
- package/src/image-tags.js +32 -16
- package/test/image_tags_test.js +69 -0
package/dist/index.cjs.js
CHANGED
|
@@ -320,6 +320,10 @@ function pickImage({ pageType, config, seoConfig, data, url }) {
|
|
|
320
320
|
*/
|
|
321
321
|
function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
322
322
|
const { image, alt, includesHost = false } = pickImage({ pageType, data, url, seoConfig, config });
|
|
323
|
+
const story = lodash.get(data, ["data", "story"]);
|
|
324
|
+
const fallbackValue = story ? false : true;
|
|
325
|
+
const isWatermarkDisabled = lodash.get(story, ["metadata", "watermark-image", "disabled"], fallbackValue);
|
|
326
|
+
const watermarkImageS3Key = lodash.get(story, ["watermark", "social", "image-s3-key"], "");
|
|
323
327
|
|
|
324
328
|
if (!image) {
|
|
325
329
|
return [];
|
|
@@ -331,15 +335,34 @@ function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
331
335
|
tags.push({ name: "robots", content: "max-image-preview:large" });
|
|
332
336
|
}
|
|
333
337
|
|
|
338
|
+
const watermarkImage = imageRatio => {
|
|
339
|
+
const imageContentParamsObj = {
|
|
340
|
+
w: 1200,
|
|
341
|
+
ar: imageRatio.join(":"),
|
|
342
|
+
auto: "format,compress",
|
|
343
|
+
ogImage: true,
|
|
344
|
+
mode: "crop",
|
|
345
|
+
overlay: watermarkImageS3Key,
|
|
346
|
+
overlay_position: "bottom",
|
|
347
|
+
overlay_width: 100
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
return `https://${config["cdn-image"]}/${image.path(imageRatio, imageContentParamsObj)}`;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const actualImage = imageRatio => {
|
|
354
|
+
const imageUrl = includesHost ? image : `https://${config["cdn-image"]}/${image.path(imageRatio, {
|
|
355
|
+
w: 1200,
|
|
356
|
+
auto: "format,compress",
|
|
357
|
+
ogImage: true,
|
|
358
|
+
enlarge: true
|
|
359
|
+
})}`;
|
|
360
|
+
return imageUrl;
|
|
361
|
+
};
|
|
334
362
|
if (seoConfig.enableTwitterCards) {
|
|
335
363
|
tags.push({
|
|
336
364
|
name: "twitter:image",
|
|
337
|
-
content:
|
|
338
|
-
w: 1200,
|
|
339
|
-
auto: "format,compress",
|
|
340
|
-
ogImage: true,
|
|
341
|
-
enlarge: true
|
|
342
|
-
})}`
|
|
365
|
+
content: isWatermarkDisabled ? actualImage([16, 9]) : watermarkImage([40, 21])
|
|
343
366
|
});
|
|
344
367
|
alt && tags.push({ property: "twitter:image:alt", content: alt });
|
|
345
368
|
}
|
|
@@ -347,12 +370,7 @@ function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
347
370
|
if (seoConfig.enableOgTags) {
|
|
348
371
|
tags.push({
|
|
349
372
|
property: "og:image",
|
|
350
|
-
content:
|
|
351
|
-
w: 1200,
|
|
352
|
-
auto: "format,compress",
|
|
353
|
-
ogImage: true,
|
|
354
|
-
enlarge: true
|
|
355
|
-
})}`
|
|
373
|
+
content: isWatermarkDisabled ? actualImage([40, 21]) : watermarkImage([40, 21])
|
|
356
374
|
});
|
|
357
375
|
tags.push({ property: "og:image:width", content: 1200 });
|
|
358
376
|
if (lodash.get(image, ["metadata", "focus-point"])) {
|
package/package.json
CHANGED
package/src/image-tags.js
CHANGED
|
@@ -112,6 +112,10 @@ function pickImage({ pageType, config, seoConfig, data, url }) {
|
|
|
112
112
|
*/
|
|
113
113
|
export function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
114
114
|
const { image, alt, includesHost = false } = pickImage({ pageType, data, url, seoConfig, config });
|
|
115
|
+
const story = get(data, ["data", "story"]);
|
|
116
|
+
const fallbackValue = story ? false : true;
|
|
117
|
+
const isWatermarkDisabled = get(story, ["metadata", "watermark-image", "disabled"], fallbackValue);
|
|
118
|
+
const watermarkImageS3Key = get(story, ["watermark", "social", "image-s3-key"], "");
|
|
115
119
|
|
|
116
120
|
if (!image) {
|
|
117
121
|
return [];
|
|
@@ -123,17 +127,36 @@ export function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
123
127
|
tags.push({ name: "robots", content: "max-image-preview:large" });
|
|
124
128
|
}
|
|
125
129
|
|
|
130
|
+
const watermarkImage = (imageRatio) => {
|
|
131
|
+
const imageContentParamsObj = {
|
|
132
|
+
w: 1200,
|
|
133
|
+
ar: imageRatio.join(":"),
|
|
134
|
+
auto: "format,compress",
|
|
135
|
+
ogImage: true,
|
|
136
|
+
mode: "crop",
|
|
137
|
+
overlay: watermarkImageS3Key,
|
|
138
|
+
overlay_position: "bottom",
|
|
139
|
+
overlay_width: 100,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return `https://${config["cdn-image"]}/${image.path(imageRatio, imageContentParamsObj)}`;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const actualImage = (imageRatio) => {
|
|
146
|
+
const imageUrl = includesHost
|
|
147
|
+
? image
|
|
148
|
+
: `https://${config["cdn-image"]}/${image.path(imageRatio, {
|
|
149
|
+
w: 1200,
|
|
150
|
+
auto: "format,compress",
|
|
151
|
+
ogImage: true,
|
|
152
|
+
enlarge: true,
|
|
153
|
+
})}`;
|
|
154
|
+
return imageUrl;
|
|
155
|
+
};
|
|
126
156
|
if (seoConfig.enableTwitterCards) {
|
|
127
157
|
tags.push({
|
|
128
158
|
name: "twitter:image",
|
|
129
|
-
content:
|
|
130
|
-
? image
|
|
131
|
-
: `https://${config["cdn-image"]}/${image.path([16, 9], {
|
|
132
|
-
w: 1200,
|
|
133
|
-
auto: "format,compress",
|
|
134
|
-
ogImage: true,
|
|
135
|
-
enlarge: true,
|
|
136
|
-
})}`,
|
|
159
|
+
content: isWatermarkDisabled ? actualImage([16, 9]) : watermarkImage([40, 21]),
|
|
137
160
|
});
|
|
138
161
|
alt && tags.push({ property: "twitter:image:alt", content: alt });
|
|
139
162
|
}
|
|
@@ -141,14 +164,7 @@ export function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
141
164
|
if (seoConfig.enableOgTags) {
|
|
142
165
|
tags.push({
|
|
143
166
|
property: "og:image",
|
|
144
|
-
content:
|
|
145
|
-
? image
|
|
146
|
-
: `https://${config["cdn-image"]}/${image.path([40, 21], {
|
|
147
|
-
w: 1200,
|
|
148
|
-
auto: "format,compress",
|
|
149
|
-
ogImage: true,
|
|
150
|
-
enlarge: true,
|
|
151
|
-
})}`,
|
|
167
|
+
content: isWatermarkDisabled ? actualImage([40, 21]) : watermarkImage([40, 21]),
|
|
152
168
|
});
|
|
153
169
|
tags.push({ property: "og:image:width", content: 1200 });
|
|
154
170
|
if (get(image, ["metadata", "focus-point"])) {
|
package/test/image_tags_test.js
CHANGED
|
@@ -17,6 +17,16 @@ describe("ImageTags", function () {
|
|
|
17
17
|
it("gets the twitter tags", function () {
|
|
18
18
|
const story = {
|
|
19
19
|
"hero-image-s3-key": "my/image.png",
|
|
20
|
+
metadata: {
|
|
21
|
+
"watermark-image": {
|
|
22
|
+
disabled: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
watermark: {
|
|
26
|
+
social: {
|
|
27
|
+
"image-s3-key": "my/watermark-image.png",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
20
30
|
alternative: {
|
|
21
31
|
social: {
|
|
22
32
|
default: {
|
|
@@ -48,6 +58,50 @@ describe("ImageTags", function () {
|
|
|
48
58
|
);
|
|
49
59
|
});
|
|
50
60
|
|
|
61
|
+
it("gets the twitter tags with watermark", function () {
|
|
62
|
+
const story = {
|
|
63
|
+
"hero-image-s3-key": "my/image.png",
|
|
64
|
+
metadata: {
|
|
65
|
+
"watermark-image": {
|
|
66
|
+
disabled: false,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
watermark: {
|
|
70
|
+
social: {
|
|
71
|
+
"image-s3-key": "my/watermark-image.png",
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
alternative: {
|
|
75
|
+
social: {
|
|
76
|
+
default: {
|
|
77
|
+
headline: null,
|
|
78
|
+
"hero-image": {
|
|
79
|
+
"hero-image-s3-key": "my/socialimage.png",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
home: {
|
|
84
|
+
default: {
|
|
85
|
+
headline: null,
|
|
86
|
+
"hero-image": {
|
|
87
|
+
"hero-image-s3-key": "my/homeimage.png",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const string = getSeoMetadata(seoConfig, config, "story-page", { data: { story: story } }, {});
|
|
94
|
+
const ampPageString = getSeoMetadata(seoConfig, config, "story-page-amp", { data: { story: story } }, {});
|
|
95
|
+
assertContains(
|
|
96
|
+
'<meta name="twitter:image" content="https://thumbor.assettype.com/my%2Fsocialimage.png?w=1200&ar=40%3A21&auto=format%2Ccompress&ogImage=true&mode=crop&overlay=my%2Fwatermark-image.png&overlay_position=bottom&overlay_width=100"/>',
|
|
97
|
+
string
|
|
98
|
+
);
|
|
99
|
+
assertContains(
|
|
100
|
+
'<meta name="twitter:image" content="https://thumbor.assettype.com/my%2Fsocialimage.png?w=1200&ar=40%3A21&auto=format%2Ccompress&ogImage=true&mode=crop&overlay=my%2Fwatermark-image.png&overlay_position=bottom&overlay_width=100"/>',
|
|
101
|
+
ampPageString
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
51
105
|
it("adds image max size tag for story page", function () {
|
|
52
106
|
const story = {
|
|
53
107
|
"hero-image-s3-key": "my/image.png",
|
|
@@ -78,6 +132,11 @@ describe("ImageTags", function () {
|
|
|
78
132
|
it("has facebook tags resized correctly", function () {
|
|
79
133
|
const story = {
|
|
80
134
|
"hero-image-s3-key": "my/images.png",
|
|
135
|
+
metadata: {
|
|
136
|
+
"watermark-image": {
|
|
137
|
+
disabled: true,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
81
140
|
"hero-image-metadata": {
|
|
82
141
|
width: 2400,
|
|
83
142
|
height: 1260,
|
|
@@ -131,6 +190,11 @@ describe("ImageTags", function () {
|
|
|
131
190
|
it("gets card image values instead of story image values on card share", function () {
|
|
132
191
|
const story = {
|
|
133
192
|
"hero-image-s3-key": "my/image.png",
|
|
193
|
+
metadata: {
|
|
194
|
+
"watermark-image": {
|
|
195
|
+
disabled: true,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
134
198
|
cards: [
|
|
135
199
|
{
|
|
136
200
|
id: "sample-card-id",
|
|
@@ -318,6 +382,11 @@ describe("ImageTags", function () {
|
|
|
318
382
|
it("gets story data as fallback if the card metadata is falsy", function () {
|
|
319
383
|
const story = {
|
|
320
384
|
"hero-image-s3-key": "my/image.png",
|
|
385
|
+
metadata: {
|
|
386
|
+
"watermark-image": {
|
|
387
|
+
disabled: true,
|
|
388
|
+
},
|
|
389
|
+
},
|
|
321
390
|
cards: [
|
|
322
391
|
{
|
|
323
392
|
id: "sample-card-id",
|