@quintype/seo 1.41.4 → 1.42.0-watermark-feature.1
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 +31 -12
- package/package.json +1 -1
- package/src/image-tags.js +35 -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,35 @@ 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
|
+
const imageUrl = includesHost ? image : `https://${config["cdn-image"]}/${image.path(imageRatio, imageContentParamsObj)}`;
|
|
351
|
+
return imageUrl;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const actualImage = imageRatio => {
|
|
355
|
+
const imageUrl = includesHost ? image : `https://${config["cdn-image"]}/${image.path(imageRatio, {
|
|
356
|
+
w: 1200,
|
|
357
|
+
auto: "format,compress",
|
|
358
|
+
ogImage: true,
|
|
359
|
+
enlarge: true
|
|
360
|
+
})}`;
|
|
361
|
+
return imageUrl;
|
|
362
|
+
};
|
|
334
363
|
if (seoConfig.enableTwitterCards) {
|
|
335
364
|
tags.push({
|
|
336
365
|
name: "twitter:image",
|
|
337
|
-
content:
|
|
338
|
-
w: 1200,
|
|
339
|
-
auto: "format,compress",
|
|
340
|
-
ogImage: true,
|
|
341
|
-
enlarge: true
|
|
342
|
-
})}`
|
|
366
|
+
content: isWatermarkDisabled ? actualImage([16, 9]) : watermarkImage([40, 21])
|
|
343
367
|
});
|
|
344
368
|
alt && tags.push({ property: "twitter:image:alt", content: alt });
|
|
345
369
|
}
|
|
@@ -347,12 +371,7 @@ function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
347
371
|
if (seoConfig.enableOgTags) {
|
|
348
372
|
tags.push({
|
|
349
373
|
property: "og:image",
|
|
350
|
-
content:
|
|
351
|
-
w: 1200,
|
|
352
|
-
auto: "format,compress",
|
|
353
|
-
ogImage: true,
|
|
354
|
-
enlarge: true
|
|
355
|
-
})}`
|
|
374
|
+
content: isWatermarkDisabled ? actualImage([40, 21]) : watermarkImage([40, 21])
|
|
356
375
|
});
|
|
357
376
|
tags.push({ property: "og:image:width", content: 1200 });
|
|
358
377
|
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,39 @@ 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
|
+
const imageUrl = includesHost
|
|
143
|
+
? image
|
|
144
|
+
: `https://${config["cdn-image"]}/${image.path(imageRatio, imageContentParamsObj)}`;
|
|
145
|
+
return imageUrl;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const actualImage = (imageRatio) => {
|
|
149
|
+
const imageUrl = includesHost
|
|
150
|
+
? image
|
|
151
|
+
: `https://${config["cdn-image"]}/${image.path(imageRatio, {
|
|
152
|
+
w: 1200,
|
|
153
|
+
auto: "format,compress",
|
|
154
|
+
ogImage: true,
|
|
155
|
+
enlarge: true,
|
|
156
|
+
})}`;
|
|
157
|
+
return imageUrl;
|
|
158
|
+
};
|
|
126
159
|
if (seoConfig.enableTwitterCards) {
|
|
127
160
|
tags.push({
|
|
128
161
|
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
|
-
})}`,
|
|
162
|
+
content: isWatermarkDisabled ? actualImage([16, 9]) : watermarkImage([40, 21]),
|
|
137
163
|
});
|
|
138
164
|
alt && tags.push({ property: "twitter:image:alt", content: alt });
|
|
139
165
|
}
|
|
@@ -141,14 +167,7 @@ export function ImageTags(seoConfig, config, pageType, data, { url = {} }) {
|
|
|
141
167
|
if (seoConfig.enableOgTags) {
|
|
142
168
|
tags.push({
|
|
143
169
|
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
|
-
})}`,
|
|
170
|
+
content: isWatermarkDisabled ? actualImage([40, 21]) : watermarkImage([40, 21]),
|
|
152
171
|
});
|
|
153
172
|
tags.push({ property: "og:image:width", content: 1200 });
|
|
154
173
|
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",
|