@times-components/ssr 2.59.38-b75a9effaef61c0e6e158c7da67c7b2543d193b4.3 → 2.59.38-c3f77517b357963002e883f8cb03f662f312dfb1.4
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/article.react.bundle.js +5 -5
- package/dist/article.react.bundle.js.map +1 -1
- package/dist/author-profile.react.bundle.js +1 -1
- package/dist/common.react.bundle.js +8 -8
- package/dist/common.react.bundle.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/affiliate-links-validation.js +18 -6
- package/src/lib/skimlinks-wrapping.js +16 -20
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@times-components/ssr",
|
|
3
3
|
"main": "src",
|
|
4
|
-
"version": "2.59.38-
|
|
4
|
+
"version": "2.59.38-c3f77517b357963002e883f8cb03f662f312dfb1.4+c3f77517b3",
|
|
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",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"publishConfig": {
|
|
81
81
|
"access": "public"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "c3f77517b357963002e883f8cb03f662f312dfb1"
|
|
84
84
|
}
|
|
@@ -3,11 +3,15 @@ const {
|
|
|
3
3
|
travelSiteCode,
|
|
4
4
|
trackonomicsRegex
|
|
5
5
|
} = require("../constants/affiliate-links-validation");
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
wrapSkimlinks,
|
|
8
|
+
fetchSkimlinksDomains,
|
|
9
|
+
filterDomains
|
|
10
|
+
} = require("./skimlinks-wrapping");
|
|
7
11
|
|
|
8
12
|
const isAffiliateLink = url => trackonomicsRegex.test(url);
|
|
9
13
|
|
|
10
|
-
const wrapAffiliateLink = (affiliateLink, contentPageUrl) => {
|
|
14
|
+
const wrapAffiliateLink = (affiliateLink, contentPageUrl, filteredDomains) => {
|
|
11
15
|
const wrapTrackonomics = trackonomicsUrl => {
|
|
12
16
|
if (!isAffiliateLink(trackonomicsUrl)) {
|
|
13
17
|
return trackonomicsUrl;
|
|
@@ -25,14 +29,20 @@ const wrapAffiliateLink = (affiliateLink, contentPageUrl) => {
|
|
|
25
29
|
return affiliateWrapper;
|
|
26
30
|
};
|
|
27
31
|
|
|
28
|
-
const skimlinksUrl = wrapSkimlinks(
|
|
32
|
+
const skimlinksUrl = wrapSkimlinks(
|
|
33
|
+
affiliateLink,
|
|
34
|
+
contentPageUrl,
|
|
35
|
+
filteredDomains
|
|
36
|
+
);
|
|
29
37
|
return wrapTrackonomics(skimlinksUrl);
|
|
30
38
|
};
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
const affiliateLinksValidation = async (children, articleDataFromRender) => {
|
|
33
41
|
const clonedChildren = [...children];
|
|
34
42
|
const { canonicalUrl, hostName } = articleDataFromRender;
|
|
35
43
|
const contentPageUrl = `${hostName}${canonicalUrl}`;
|
|
44
|
+
const skimlinksDomains = await fetchSkimlinksDomains();
|
|
45
|
+
const filteredDomains = filterDomains(skimlinksDomains);
|
|
36
46
|
|
|
37
47
|
const checkAndSetLinkTarget = elements =>
|
|
38
48
|
elements.map(el => {
|
|
@@ -66,7 +76,7 @@ module.exports.affiliateLinksValidation = (children, articleDataFromRender) => {
|
|
|
66
76
|
attributes: {
|
|
67
77
|
...attributes,
|
|
68
78
|
target: "_blank",
|
|
69
|
-
url: wrapAffiliateLink(href, contentPageUrl)
|
|
79
|
+
url: wrapAffiliateLink(href, contentPageUrl, filteredDomains)
|
|
70
80
|
}
|
|
71
81
|
};
|
|
72
82
|
} else {
|
|
@@ -75,7 +85,7 @@ module.exports.affiliateLinksValidation = (children, articleDataFromRender) => {
|
|
|
75
85
|
attributes: {
|
|
76
86
|
...attributes,
|
|
77
87
|
target: "_blank",
|
|
78
|
-
href: wrapAffiliateLink(href, contentPageUrl)
|
|
88
|
+
href: wrapAffiliateLink(href, contentPageUrl, filteredDomains)
|
|
79
89
|
}
|
|
80
90
|
};
|
|
81
91
|
}
|
|
@@ -91,3 +101,5 @@ module.exports.affiliateLinksValidation = (children, articleDataFromRender) => {
|
|
|
91
101
|
|
|
92
102
|
return checkAndSetLinkTarget(clonedChildren);
|
|
93
103
|
};
|
|
104
|
+
|
|
105
|
+
module.exports = { affiliateLinksValidation };
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
// eslint-disable-next-line no-unused-vars
|
|
2
1
|
const { flowRight } = require("lodash");
|
|
3
|
-
|
|
2
|
+
const { publisherId } = require("../constants/affiliate-links-validation");
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
const getSecondLevelDomain = str => str.replace(/^(https?:\/\/)?www\./, "");
|
|
6
5
|
|
|
7
6
|
const trim = str => str.trim();
|
|
8
7
|
|
|
9
8
|
const removeTrailingSlash = str => str.replace(/\/$/, "");
|
|
10
9
|
|
|
11
|
-
const stringifyArg = str => (typeof str === "string" ? str : "");
|
|
10
|
+
const stringifyArg = str => (typeof str === "string" ? str : "");
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Removes http scheme, `www.`, and trailing slash from the string
|
|
15
14
|
* @param str
|
|
16
15
|
* @returns Domain name without www
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
const sanitizeDomainName = flowRight(
|
|
19
18
|
removeTrailingSlash,
|
|
20
19
|
getSecondLevelDomain,
|
|
21
20
|
trim,
|
|
22
21
|
stringifyArg
|
|
23
|
-
);
|
|
22
|
+
);
|
|
24
23
|
|
|
25
24
|
const fetchSkimlinksDomains = async () => {
|
|
26
25
|
const response = await fetch(
|
|
@@ -41,17 +40,17 @@ const fetchSkimlinksDomains = async () => {
|
|
|
41
40
|
* @param domains List of domains
|
|
42
41
|
* @returns Array of just retailer domains
|
|
43
42
|
*/
|
|
44
|
-
|
|
43
|
+
const filterDomains = domains =>
|
|
45
44
|
Array.isArray(domains)
|
|
46
45
|
? domains.map(retailer => retailer.domain).map(sanitizeDomainName)
|
|
47
|
-
: [];
|
|
46
|
+
: [];
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
const createDomainRegex = domains => {
|
|
50
49
|
const domainRegexString = domains.join("|");
|
|
51
50
|
const skimlinksRegex = new RegExp(domainRegexString);
|
|
52
51
|
|
|
53
52
|
return skimlinksRegex;
|
|
54
|
-
};
|
|
53
|
+
};
|
|
55
54
|
|
|
56
55
|
/**
|
|
57
56
|
*
|
|
@@ -59,29 +58,26 @@ const fetchSkimlinksDomains = async () => {
|
|
|
59
58
|
* @param contentPageUrl The referring page
|
|
60
59
|
* @returns Skimlinks url
|
|
61
60
|
*/
|
|
62
|
-
|
|
61
|
+
const constructSkimlinksUrl = (merchantUrl, contentPageUrl) => {
|
|
63
62
|
const skimlinksWrapper = `https://go.skimresources.com/?id=${publisherId}&url=${encodeURIComponent(
|
|
64
63
|
merchantUrl
|
|
65
64
|
)}&sref=${encodeURIComponent(contentPageUrl)}`;
|
|
66
65
|
|
|
67
66
|
return skimlinksWrapper;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const wrapSkimlinks = async url => {
|
|
71
|
-
const data = await fetchSkimlinksDomains();
|
|
67
|
+
};
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
console.log("data: ", data);
|
|
75
|
-
/* const filteredDomains = filterDomains(data);
|
|
69
|
+
const wrapSkimlinks = (url, contentPageUrl, filteredDomains) => {
|
|
76
70
|
const skimlinksRegex = createDomainRegex(filteredDomains);
|
|
77
71
|
|
|
78
72
|
if (skimlinksRegex.test(url)) {
|
|
79
73
|
return constructSkimlinksUrl(url, contentPageUrl);
|
|
80
|
-
}
|
|
74
|
+
}
|
|
81
75
|
|
|
82
76
|
return url;
|
|
83
77
|
};
|
|
84
78
|
|
|
85
79
|
module.exports = {
|
|
86
|
-
wrapSkimlinks
|
|
80
|
+
wrapSkimlinks,
|
|
81
|
+
fetchSkimlinksDomains,
|
|
82
|
+
filterDomains
|
|
87
83
|
};
|