@quintype/seo 1.50.1 → 1.50.2-aff-mkt-template.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 CHANGED
@@ -1060,6 +1060,7 @@ function StructuredDataTags({ structuredData = {} }, config, pageType, response
1060
1060
  const structuredDataTags = get__default["default"](structuredData, ["structuredDataTags"], []);
1061
1061
  const enableEventsData = get__default["default"](structuredData, ["enableEventsData"], null);
1062
1062
  const enableStorySeoEventsData = get__default["default"](story, ["enableSeoEventsData"], null);
1063
+ const enableAffiliateMarketing = get__default["default"](structuredData, ["enableAffiliateMarketing"], false);
1063
1064
  let articleData = {};
1064
1065
 
1065
1066
  if (!isStructuredDataEmpty) {
@@ -1094,6 +1095,13 @@ function StructuredDataTags({ structuredData = {} }, config, pageType, response
1094
1095
  newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
1095
1096
  }
1096
1097
 
1098
+ if (enableAffiliateMarketing && !isStructuredDataEmpty && pageType === "story-page" && story["story-template"] === "affiliate-marketing") {
1099
+ const affiliateProductTags = generateAffiliateProductData();
1100
+ if (affiliateProductTags) {
1101
+ affiliateProductTags.forEach(tag => tags.push(tag));
1102
+ }
1103
+ }
1104
+
1097
1105
  if (!isStructuredDataEmpty && pageType === "story-page-amp") {
1098
1106
  const newsArticleTags = generateNewsArticleTags();
1099
1107
  newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
@@ -1187,6 +1195,48 @@ function StructuredDataTags({ structuredData = {} }, config, pageType, response
1187
1195
  return ldJson("MediaGallery", schema);
1188
1196
  }
1189
1197
 
1198
+ function generateAffiliateProductData() {
1199
+ const storyUrl = story.url || `${publisherConfig["sketches-host"]}/${story.slug}`;
1200
+ const authorName = get__default["default"](story, ["authors", 0, "name"]) || story["author-name"] || "";
1201
+ const datePublished = stripMillisecondsFromTime(new Date(story["first-published-at"]), timezone);
1202
+ const cards = get__default["default"](story, ["cards"], []);
1203
+
1204
+ const products = cards.reduce((acc, card) => {
1205
+ const elements = get__default["default"](card, ["story-elements"], []);
1206
+ const titleEl = elements.find(el => el.type === "title");
1207
+ if (!titleEl) return acc;
1208
+
1209
+ const name = getPlainText(titleEl.text || titleEl.title || "");
1210
+ if (!name) return acc;
1211
+
1212
+ const imageEl = elements.find(el => el.type === "image");
1213
+ const ctaEl = elements.find(el => el.type === "text" && el.subtype === "cta");
1214
+ const textEl = elements.find(el => el.type === "text" && el.subtype !== "cta");
1215
+ const reviewBody = getPlainText(get__default["default"](textEl, ["text"], ""));
1216
+ const ctaUrl = get__default["default"](ctaEl, ["metadata", "cta-url"]);
1217
+
1218
+ const product = {
1219
+ name,
1220
+ url: ctaUrl || `${storyUrl}#${card.id}`,
1221
+ review: {
1222
+ "@type": "Review",
1223
+ author: getSchemaPerson(authorName),
1224
+ reviewBody,
1225
+ datePublished
1226
+ }
1227
+ };
1228
+
1229
+ if (imageEl && imageEl["image-s3-key"]) {
1230
+ product.image = imageUrl(publisherConfig, imageEl["image-s3-key"]);
1231
+ }
1232
+
1233
+ acc.push(ldJson("Product", product));
1234
+ return acc;
1235
+ }, []);
1236
+
1237
+ return products.length ? products : null;
1238
+ }
1239
+
1190
1240
  // All Pages have: Publisher, Site
1191
1241
  // Story Page have : Article/NewsArticle/LiveBlog/Review as appropriate
1192
1242
  return tags;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/seo",
3
- "version": "1.50.1",
3
+ "version": "1.50.2-aff-mkt-template.0",
4
4
  "description": "SEO Modules for Quintype",
5
5
  "main": "dist/index.cjs.js",
6
6
  "repository": "https://github.com/quintype/quintype-node-seo",
@@ -564,6 +564,7 @@ export function StructuredDataTags({ structuredData = {} }, config, pageType, re
564
564
  const structuredDataTags = get(structuredData, ["structuredDataTags"], []);
565
565
  const enableEventsData = get(structuredData, ["enableEventsData"], null);
566
566
  const enableStorySeoEventsData = get(story, ["enableSeoEventsData"], null);
567
+ const enableAffiliateMarketing = get(structuredData, ["enableAffiliateMarketing"], false);
567
568
  let articleData = {};
568
569
 
569
570
  if (!isStructuredDataEmpty) {
@@ -598,6 +599,13 @@ export function StructuredDataTags({ structuredData = {} }, config, pageType, re
598
599
  newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
599
600
  }
600
601
 
602
+ if (enableAffiliateMarketing && !isStructuredDataEmpty && pageType === "story-page" && story["story-template"] === "affiliate-marketing") {
603
+ const affiliateProductTags = generateAffiliateProductData();
604
+ if (affiliateProductTags) {
605
+ affiliateProductTags.forEach((tag) => tags.push(tag));
606
+ }
607
+ }
608
+
601
609
  if (!isStructuredDataEmpty && pageType === "story-page-amp") {
602
610
  const newsArticleTags = generateNewsArticleTags();
603
611
  newsArticleTags ? tags.push(storyTags(), newsArticleTags) : tags.push(storyTags());
@@ -700,6 +708,48 @@ export function StructuredDataTags({ structuredData = {} }, config, pageType, re
700
708
  return ldJson("MediaGallery", schema);
701
709
  }
702
710
 
711
+ function generateAffiliateProductData() {
712
+ const storyUrl = story.url || `${publisherConfig["sketches-host"]}/${story.slug}`;
713
+ const authorName = get(story, ["authors", 0, "name"]) || story["author-name"] || "";
714
+ const datePublished = stripMillisecondsFromTime(new Date(story["first-published-at"]), timezone);
715
+ const cards = get(story, ["cards"], []);
716
+
717
+ const products = cards.reduce((acc, card) => {
718
+ const elements = get(card, ["story-elements"], []);
719
+ const titleEl = elements.find((el) => el.type === "title");
720
+ if (!titleEl) return acc;
721
+
722
+ const name = getPlainText(titleEl.text || titleEl.title || "");
723
+ if (!name) return acc;
724
+
725
+ const imageEl = elements.find((el) => el.type === "image");
726
+ const ctaEl = elements.find((el) => el.type === "text" && el.subtype === "cta");
727
+ const textEl = elements.find((el) => el.type === "text" && el.subtype !== "cta");
728
+ const reviewBody = getPlainText(get(textEl, ["text"], ""));
729
+ const ctaUrl = get(ctaEl, ["metadata", "cta-url"]);
730
+
731
+ const product = {
732
+ name,
733
+ url: ctaUrl || `${storyUrl}#${card.id}`,
734
+ review: {
735
+ "@type": "Review",
736
+ author: getSchemaPerson(authorName),
737
+ reviewBody,
738
+ datePublished,
739
+ },
740
+ };
741
+
742
+ if (imageEl && imageEl["image-s3-key"]) {
743
+ product.image = imageUrl(publisherConfig, imageEl["image-s3-key"]);
744
+ }
745
+
746
+ acc.push(ldJson("Product", product));
747
+ return acc;
748
+ }, []);
749
+
750
+ return products.length ? products : null;
751
+ }
752
+
703
753
  // All Pages have: Publisher, Site
704
754
  // Story Page have : Article/NewsArticle/LiveBlog/Review as appropriate
705
755
  return tags;