@quintype/seo 1.49.2 → 1.49.3-article-image-array-schema.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 CHANGED
@@ -680,10 +680,44 @@ function generateArticleData(structuredData = {}, story = {}, publisherConfig =
680
680
  dateModified: stripMillisecondsFromTime(new Date(story["last-published-at"]), timezone),
681
681
  datePublished: stripMillisecondsFromTime(new Date(story["first-published-at"]), timezone),
682
682
  name: storyKeysPresence && story.headline || "",
683
- image: generateArticleImageData(story["hero-image-s3-key"], publisherConfig)
683
+ image: generateArticleHeroImageData(story["hero-image-s3-key"], publisherConfig, story["hero-image-metadata"])
684
684
  }, isAccessibleForFree, sponsor, { isPartOf: generateIsPartOfDataForArticle(story, publisherConfig) }, articleSectionObj(story));
685
685
  }
686
686
 
687
+ function generateArticleHeroImageData(image, publisherConfig = {}, imageMetadata = {}) {
688
+ const imageWidth = 1200;
689
+ const imageHeights = [675, 900, 1200];
690
+ const hasFocusPoint = get__default["default"](imageMetadata, ["focus-point"], null);
691
+
692
+ const focusedImage = hasFocusPoint ? new quintypeJs.FocusedImage(image, imageMetadata) : null;
693
+
694
+ return imageHeights.map(height => {
695
+ let croppedImage = "";
696
+ const imageSrc = /^https?.*/.test(publisherConfig["cdn-image"]) ? publisherConfig["cdn-image"] : `https://${publisherConfig["cdn-image"]}`;
697
+
698
+ if (focusedImage) {
699
+ const path = focusedImage.path([imageWidth, height], {
700
+ w: imageWidth,
701
+ h: height,
702
+ auto: "format,compress",
703
+ fit: "crop"
704
+ });
705
+ croppedImage = `${imageSrc}/${path}`;
706
+ console.log("focusedImage ----------->>>", {
707
+ hasFocusPoint,
708
+ focusedImage,
709
+ path,
710
+ croppedImage
711
+ });
712
+ }
713
+ const finalUrl = focusedImage ? croppedImage : imageUrl(publisherConfig, image, imageWidth, height);
714
+ return Object.assign({
715
+ "@type": "ImageObject",
716
+ url: finalUrl
717
+ }, getQueryParams(finalUrl));
718
+ });
719
+ }
720
+
687
721
  function generateArticleImageData(image, publisherConfig = {}) {
688
722
  const imageWidth = 1200;
689
723
  const imageHeight = 675;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/seo",
3
- "version": "1.49.2",
3
+ "version": "1.49.3-article-image-array-schema.1",
4
4
  "description": "SEO Modules for Quintype",
5
5
  "main": "dist/index.cjs.js",
6
6
  "repository": "https://github.com/quintype/quintype-node-seo",
@@ -1,4 +1,5 @@
1
1
  import get from "lodash/get";
2
+ import { FocusedImage } from "quintype-js";
2
3
  import { getAllowedCards, getQueryParams, stripMillisecondsFromTime, stripQueryParams } from "../utils";
3
4
  import { generateTagsForEntity } from "./entity";
4
5
  import {
@@ -122,7 +123,7 @@ function generateArticleData(structuredData = {}, story = {}, publisherConfig =
122
123
  dateModified: stripMillisecondsFromTime(new Date(story["last-published-at"]), timezone),
123
124
  datePublished: stripMillisecondsFromTime(new Date(story["first-published-at"]), timezone),
124
125
  name: (storyKeysPresence && story.headline) || "",
125
- image: generateArticleImageData(story["hero-image-s3-key"], publisherConfig),
126
+ image: generateArticleHeroImageData(story["hero-image-s3-key"], publisherConfig, story["hero-image-metadata"]),
126
127
  },
127
128
  isAccessibleForFree,
128
129
  sponsor,
@@ -131,6 +132,45 @@ function generateArticleData(structuredData = {}, story = {}, publisherConfig =
131
132
  );
132
133
  }
133
134
 
135
+ function generateArticleHeroImageData(image, publisherConfig = {}, imageMetadata = {}) {
136
+ const imageWidth = 1200;
137
+ const imageHeights = [675, 900, 1200];
138
+ const hasFocusPoint = get(imageMetadata, ["focus-point"], null);
139
+
140
+ const focusedImage = hasFocusPoint ? new FocusedImage(image, imageMetadata) : null;
141
+
142
+ return imageHeights.map((height) => {
143
+ let croppedImage = "";
144
+ const imageSrc = /^https?.*/.test(publisherConfig["cdn-image"])
145
+ ? publisherConfig["cdn-image"]
146
+ : `https://${publisherConfig["cdn-image"]}`;
147
+
148
+ if (focusedImage) {
149
+ const path = focusedImage.path([imageWidth, height], {
150
+ w: imageWidth,
151
+ h: height,
152
+ auto: "format,compress",
153
+ fit: "crop",
154
+ });
155
+ croppedImage = `${imageSrc}/${path}`;
156
+ console.log("focusedImage ----------->>>", {
157
+ hasFocusPoint,
158
+ focusedImage,
159
+ path,
160
+ croppedImage,
161
+ });
162
+ }
163
+ const finalUrl = focusedImage ? croppedImage : imageUrl(publisherConfig, image, imageWidth, height);
164
+ return Object.assign(
165
+ {
166
+ "@type": "ImageObject",
167
+ url: finalUrl,
168
+ },
169
+ getQueryParams(finalUrl)
170
+ );
171
+ });
172
+ }
173
+
134
174
  function generateArticleImageData(image, publisherConfig = {}) {
135
175
  const imageWidth = 1200;
136
176
  const imageHeight = 675;