@times-components/ssr 2.59.37-046150db36af324c2d3b86a7678c43de4c8def9c.17 → 2.59.37-1cf7d53b4588143a651811d12b4d5a1288605704.22

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@times-components/ssr",
3
3
  "main": "src",
4
- "version": "2.59.37-046150db36af324c2d3b86a7678c43de4c8def9c.17+046150db36",
4
+ "version": "2.59.37-1cf7d53b4588143a651811d12b4d5a1288605704.22+1cf7d53b45",
5
5
  "scripts": {
6
6
  "bundle:dev": "yarn cleanup-dist && webpack --config=webpack.config.js",
7
7
  "bundle:prod": "yarn cleanup-dist && NODE_ENV=production webpack --config=webpack.config.js -p",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "046150db36af324c2d3b86a7678c43de4c8def9c"
82
+ "gitHead": "1cf7d53b4588143a651811d12b4d5a1288605704"
83
83
  }
@@ -13,7 +13,9 @@ const {
13
13
  defaults
14
14
  } = require("@times-components/context/rnw");
15
15
  const { scales, themeFactory } = require("@times-components/ts-styleguide/rnw");
16
- const { setExternalLinkTargets } = require("../lib/set-external-links");
16
+ const {
17
+ affiliateLinksValidation
18
+ } = require("../lib/affiliate-links-validation");
17
19
 
18
20
  const scale = scales.large;
19
21
 
@@ -60,12 +62,15 @@ module.exports = (client, analyticsStream, data, helmetContext) => {
60
62
  ? providerData.draftArticle
61
63
  : providerData.article;
62
64
  const articleTemplate = article ? article.template : null;
63
- const formattedArticle = article.content.map(contentItem =>
64
- setExternalLinkTargets(contentItem.children)
65
+ const articleContent = affiliateLinksValidation(
66
+ article.content,
67
+ articleDataFromRender
65
68
  );
66
69
 
70
+ const formattedArticle = { ...article, content: articleContent };
71
+
67
72
  // eslint-disable-next-line no-console
68
- console.log("Article: ", article);
73
+ console.log("Article: ", article, articleDataFromRender);
69
74
 
70
75
  // eslint-disable-next-line no-console
71
76
  console.log("Formatted Article: ", formattedArticle);
@@ -3,12 +3,10 @@ const {
3
3
  travelSiteCode,
4
4
  skimlinksId,
5
5
  regexTrackonomics
6
- } = require("./affiliate-validation");
6
+ } = require("../constants/affiliate-validation");
7
7
 
8
- const wrapAffiliateLink = affiliateLink => {
8
+ const wrapAffiliateLink = (affiliateLink, contentPageUrl) => {
9
9
  const wrapTrackonomics = trackonomicsUrl => {
10
- const contentPageUrl =
11
- "https://www.thetimes.com/travel/inspiration/tour-holidays/adventurous-summer-holidays-kklt22gp8";
12
10
  const isTravel =
13
11
  contentPageUrl.includes("https://www.thetimes.com/travel") ||
14
12
  contentPageUrl.includes("https://www.thetimes.co.uk/travel");
@@ -17,8 +15,7 @@ const wrapAffiliateLink = affiliateLink => {
17
15
  return trackonomicsUrl;
18
16
  }
19
17
 
20
- const referrerUrl =
21
- "https://www.thetimes.com/travel/inspiration/tour-holidays/adventurous-summer-holidays-kklt22gp8";
18
+ const referrerUrl = "";
22
19
  const siteCode = isTravel ? travelSiteCode : theTimesSiteCode;
23
20
  const affiliateWrapper = `https://clicks.trx-hub.com/xid/${siteCode}?q=${encodeURIComponent(
24
21
  trackonomicsUrl
@@ -30,8 +27,6 @@ const wrapAffiliateLink = affiliateLink => {
30
27
  };
31
28
 
32
29
  const wrapSkimlinks = skimlinkUrl => {
33
- const contentPageUrl =
34
- "https://www.thetimes.com/travel/inspiration/tour-holidays/adventurous-summer-holidays-kklt22gp8";
35
30
  const affiliateWrapper = `https://go.skimresources.com/?id=${skimlinksId}&url=${encodeURIComponent(
36
31
  skimlinkUrl
37
32
  )}&sref=${encodeURIComponent(contentPageUrl)}`;
@@ -43,8 +38,10 @@ const wrapAffiliateLink = affiliateLink => {
43
38
  return wrapTrackonomics(wrapInSkimlinks);
44
39
  };
45
40
 
46
- module.exports.setExternalLinkTargets = children => {
41
+ module.exports.affiliateLinksValidation = (children, articleDataFromRender) => {
47
42
  const clonedChildren = [...children];
43
+ const { canonicalUrl, hostName } = articleDataFromRender;
44
+ const contentPageUrl = `${hostName}${canonicalUrl}`;
48
45
 
49
46
  const checkAndSetLinkTarget = elements =>
50
47
  elements.map(el => {
@@ -78,7 +75,7 @@ module.exports.setExternalLinkTargets = children => {
78
75
  attributes: {
79
76
  ...attributes,
80
77
  target: "_blank",
81
- url: wrapAffiliateLink(href)
78
+ url: wrapAffiliateLink(href, contentPageUrl)
82
79
  }
83
80
  };
84
81
  } else {
@@ -87,7 +84,7 @@ module.exports.setExternalLinkTargets = children => {
87
84
  attributes: {
88
85
  ...attributes,
89
86
  target: "_blank",
90
- href: wrapAffiliateLink(href)
87
+ href: wrapAffiliateLink(href, contentPageUrl)
91
88
  }
92
89
  };
93
90
  }
File without changes