@mjhls/mjh-framework 1.0.665-beta.0 → 1.0.665-beta.3
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/cjs/View.js +48 -37
- package/dist/cjs/getQuery.js +1 -1
- package/dist/cjs/getRelatedArticle.js +440 -6
- package/dist/cjs/index.js +2 -2
- package/dist/esm/View.js +46 -35
- package/dist/esm/getQuery.js +1 -1
- package/dist/esm/getRelatedArticle.js +443 -5
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/getRelatedArticle-606b1d0b.js +0 -447
- package/dist/esm/getRelatedArticle-80e67416.js +0 -443
package/dist/esm/View.js
CHANGED
|
@@ -53,7 +53,7 @@ import { _ as _Object$keys } from './keys-fc2d4c34.js';
|
|
|
53
53
|
import 'react-bootstrap/Dropdown';
|
|
54
54
|
import getSeriesDetail from './getSeriesDetail.js';
|
|
55
55
|
import './index-db3bb315.js';
|
|
56
|
-
import
|
|
56
|
+
import getRelatedArticle from './getRelatedArticle.js';
|
|
57
57
|
import getQuery from './getQuery.js';
|
|
58
58
|
import { g as getTargeting, a as getContentPlacementUrl } from './getTargeting-2acdec91.js';
|
|
59
59
|
import getKeywords from './getKeywords.js';
|
|
@@ -440,7 +440,7 @@ var Article = function Article(props) {
|
|
|
440
440
|
);
|
|
441
441
|
}),
|
|
442
442
|
content_placement && content_placement.length > 0 ? content_placement.filter(function (item) {
|
|
443
|
-
return item.
|
|
443
|
+
return item.path !== 'news';
|
|
444
444
|
}).map(function (cp, index) {
|
|
445
445
|
var cp_url = cpModificationRequired ? getContentPlacementUrl(cp) : cp.path;
|
|
446
446
|
var href = '/' + cp_url;
|
|
@@ -1014,13 +1014,12 @@ var _this = undefined;
|
|
|
1014
1014
|
|
|
1015
1015
|
var getRelatedContents = function () {
|
|
1016
1016
|
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
|
|
1017
|
-
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1018
1017
|
var client = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1019
1018
|
var article = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1020
1019
|
var prevUrl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '/';
|
|
1021
1020
|
var articleCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
1022
1021
|
|
|
1023
|
-
var _article$url, url, content_placement, documentGroupMapping, issueGroup, params, conditions, taxonomy, documentGroup,
|
|
1022
|
+
var _article$url, url, content_placement, documentGroupMapping, issueGroup, params, conditions, taxonomy, documentGroup, relatedContents, relatedContentQuery;
|
|
1024
1023
|
|
|
1025
1024
|
return regenerator.wrap(function _callee$(_context) {
|
|
1026
1025
|
while (1) {
|
|
@@ -1032,8 +1031,7 @@ var getRelatedContents = function () {
|
|
|
1032
1031
|
} : _article$url;
|
|
1033
1032
|
url = _article$url.current, content_placement = article.content_placement, documentGroupMapping = article.documentGroupMapping, issueGroup = article.issueGroup;
|
|
1034
1033
|
params = {
|
|
1035
|
-
url: url
|
|
1036
|
-
index: articleCount
|
|
1034
|
+
url: url
|
|
1037
1035
|
};
|
|
1038
1036
|
conditions = '';
|
|
1039
1037
|
|
|
@@ -1055,15 +1053,20 @@ var getRelatedContents = function () {
|
|
|
1055
1053
|
}
|
|
1056
1054
|
if (prev_url_to_check.endsWith(path) && _id) taxonomy.push(_id);
|
|
1057
1055
|
});
|
|
1058
|
-
if (taxonomy.length === 0)
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1056
|
+
if (taxonomy.length === 0) {
|
|
1057
|
+
content_placement.filter(function (_ref3) {
|
|
1058
|
+
var identifier = _ref3.identifier;
|
|
1059
|
+
return identifier !== 'news';
|
|
1060
|
+
}).forEach(function (_ref4) {
|
|
1061
|
+
var _id = _ref4._id;
|
|
1062
|
+
|
|
1063
|
+
if (_id) taxonomy.push(_id);
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
if (taxonomy.length > 0) {
|
|
1067
|
+
params = _extends({}, params, { taxonomy: taxonomy });
|
|
1068
|
+
conditions = '&& taxonomyMapping[]._ref in $taxonomy';
|
|
1069
|
+
}
|
|
1067
1070
|
}
|
|
1068
1071
|
|
|
1069
1072
|
if (documentGroupMapping && documentGroupMapping.length > 0) {
|
|
@@ -1074,48 +1077,56 @@ var getRelatedContents = function () {
|
|
|
1074
1077
|
|
|
1075
1078
|
if (_id) documentGroup.push(_id);
|
|
1076
1079
|
});
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
if (issueGroup) {
|
|
1082
|
-
params = _extends({}, params, { issueAssociation: issueGroup._ref });
|
|
1083
|
-
conditions = conditions.concat('&& issueGroup._ref == $issueAssociation ');
|
|
1080
|
+
if (params.taxonomy && documentGroup.length > 0) {
|
|
1081
|
+
params = _extends({}, params, { documentGroup: documentGroup });
|
|
1082
|
+
conditions = '&& (taxonomyMapping[]._ref in $taxonomy || documentGroupMapping[]._ref in $documentGroup)';
|
|
1083
|
+
}
|
|
1084
1084
|
}
|
|
1085
1085
|
|
|
1086
|
-
if (
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
if (
|
|
1091
|
-
|
|
1092
|
-
conditions = '&&
|
|
1093
|
-
}
|
|
1086
|
+
if (issueGroup && issueGroup._ref) {
|
|
1087
|
+
if (params.taxonomy && params.documentGroup) {
|
|
1088
|
+
params = _extends({}, params, { issueAssociation: issueGroup._ref });
|
|
1089
|
+
conditions = '&& (taxonomyMapping[]._ref in $taxonomy || documentGroupMapping[]._ref in $documentGroup || issueGroup._ref == $issueAssociation )';
|
|
1090
|
+
} else if (params.taxonomy) {
|
|
1091
|
+
params = _extends({}, params, { issueAssociation: issueGroup._ref });
|
|
1092
|
+
conditions = '&& (taxonomyMapping[]._ref in $taxonomy || issueGroup._ref == $issueAssociation )';
|
|
1093
|
+
}
|
|
1094
1094
|
}
|
|
1095
1095
|
|
|
1096
1096
|
relatedContents = [];
|
|
1097
1097
|
|
|
1098
1098
|
if (!(params.taxonomy && params.taxonomy.length > 0)) {
|
|
1099
|
-
_context.next =
|
|
1099
|
+
_context.next = 21;
|
|
1100
1100
|
break;
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
|
-
relatedContentQuery =
|
|
1103
|
+
relatedContentQuery = '*[\n _type == "article"\n && defined(title)\n && defined(url)\n && !(_id in path("drafts.**"))\n && taxonomyMapping[].disableAds != \'true\'\n && contentCategory.name != \'Poll\'\n && contentCategory.name != \'Slideshows\'\n \t&& contentCategory.disableAds != \'true\'\n && ExcludeFromInfiniteScroll !=true\n && url.current != $url\n && !defined(body[].videos)\n && published <= \'' + new Date().toISOString() + '\'\n ' + conditions + '\n\n // && is_visible == true\n // && passwordLock!=true\n\n\n ]| order(published desc)[' + articleCount + ']\n {\n title,\n url,\n thumbnail\n }';
|
|
1104
|
+
_context.prev = 11;
|
|
1104
1105
|
_context.next = 14;
|
|
1105
1106
|
return client.fetch(relatedContentQuery, params);
|
|
1106
1107
|
|
|
1107
1108
|
case 14:
|
|
1108
1109
|
relatedContents = _context.sent;
|
|
1109
1110
|
|
|
1110
|
-
|
|
1111
|
+
debugger;
|
|
1112
|
+
_context.next = 21;
|
|
1113
|
+
break;
|
|
1114
|
+
|
|
1115
|
+
case 18:
|
|
1116
|
+
_context.prev = 18;
|
|
1117
|
+
_context.t0 = _context['catch'](11);
|
|
1118
|
+
|
|
1119
|
+
console.error(_context.t0);
|
|
1120
|
+
|
|
1121
|
+
case 21:
|
|
1111
1122
|
return _context.abrupt('return', relatedContents);
|
|
1112
1123
|
|
|
1113
|
-
case
|
|
1124
|
+
case 22:
|
|
1114
1125
|
case 'end':
|
|
1115
1126
|
return _context.stop();
|
|
1116
1127
|
}
|
|
1117
1128
|
}
|
|
1118
|
-
}, _callee, _this);
|
|
1129
|
+
}, _callee, _this, [[11, 18]]);
|
|
1119
1130
|
}));
|
|
1120
1131
|
|
|
1121
1132
|
return function getRelatedContents() {
|
package/dist/esm/getQuery.js
CHANGED
|
@@ -8,7 +8,7 @@ var getQuery = function getQuery(type) {
|
|
|
8
8
|
|
|
9
9
|
switch (type) {
|
|
10
10
|
case 'related':
|
|
11
|
-
return '*[\n _type == "article"\n && defined(title)\n && defined(url)\n && !(_id in path("drafts.**"))\n && is_visible == true\n && published <= now()\n && passwordLock!=true\n && taxonomyMapping[]._ref in $taxonomy\n && taxonomyMapping[].disableAds != \'true\'\n && contentCategory->.name != \'Poll\'\n && contentCategory->.name != \'Slideshows\'\n && contentCategory->.disableAds != \'true\'\n && ExcludeFromInfiniteScroll !=true\n && url.current != $url\n && !defined(body[].videos)\n ' + conditions + '\n ]| order(published desc)[' + (articleCount ? articleCount : '$index') + ']{\n ' + params + '\n title,\n published,\n summary,\n thumbnail,\n ...,\n passwordLock,\n password,\n "authorDetails": authorMapping[]->{ displayName, url, profileImage, biography },\n body[] {\n ...,\n upload_doc {\n _type,\n asset->\n },\n uploadAudio {\n _type,\n asset->\n }\n },\n \'content_placement\': taxonomyMapping[]-> {\n _id,\n \'ancestor\': parent->parent->identifier,\n \'parent\': parent->identifier,\n \'name\': name,\n \'path\': identifier,\n disableAds\n },\n documentGroup-> {\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n documentGroupMapping[]-> {\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n \'issue\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.issueGroup._ref][0] {\n name,\n \'path\': identifier.current,\n \'publication\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.parent._ref][0] {\n name,\n \'path\': identifier.current\n },\n \'url\' : pdf.asset-> url\n }\n }';
|
|
11
|
+
return '*[\n _type == "article"\n && defined(title)\n && defined(url)\n && !(_id in path("drafts.**"))\n && is_visible == true\n && published <= now()\n && passwordLock!=true\n && taxonomyMapping[]._ref in $taxonomy\n && taxonomyMapping[].disableAds != \'true\'\n && contentCategory->.name != \'Poll\'\n && contentCategory->.name != \'Slideshows\'\n && contentCategory->.disableAds != \'true\'\n && ExcludeFromInfiniteScroll !=true\n && url.current != $url\n && !defined(body[].videos)\n ' + conditions + '\n ]| order(published desc)[' + (articleCount ? articleCount : '$index') + ']{\n ' + params + '\n title,\n published,\n summary,\n thumbnail,\n ...,\n passwordLock,\n password,\n "authorDetails": authorMapping[]->{ displayName, url, profileImage, biography },\n body[] {\n ...,\n upload_doc {\n _type,\n asset->\n },\n uploadAudio {\n _type,\n asset->\n }\n },\n \'content_placement\': taxonomyMapping[]-> {\n _id,\n \'ancestor\': parent->parent->identifier,\n \'parent\': parent->identifier,\n \'name\': name,\n \'path\': identifier,\n disableAds\n },\n documentGroup-> {\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n documentGroupMapping[]-> {\n _id,\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n \'issue\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.issueGroup._ref][0] {\n name,\n \'path\': identifier.current,\n \'publication\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.parent._ref][0] {\n name,\n \'path\': identifier.current\n },\n \'url\' : pdf.asset-> url\n }\n }';
|
|
12
12
|
case 'article':
|
|
13
13
|
return '*[\n _type == "article"\n && !(_id in path("drafts.**"))\n && defined(title)\n && defined(url)\n && url.current == $url\n ' + conditions + '\n ][0]{\n ' + params + '\n title,\n published,\n summary,\n thumbnail,\n ...,\n passwordLock,\n password,\n "authorDetails": authorMapping[]->{ displayName, url, profileImage, biography },\n body[] {\n ...,\n upload_doc {\n _type,\n asset->\n },\n uploadAudio {\n _type,\n asset->\n },\n medias[]{\n ...,\n upload_doc {\n _type,\n asset-> \n } \n },\n articles[]{\n ...,\n "authorDetails": authorMapping[]->{ displayName, url, profileImage, biography },\n }\n },\n \'content_placement\': taxonomyMapping[]-> {\n ...,\n \'ancestor\': parent->parent->identifier,\n \'parent\': parent->identifier,\n \'name\': name,\n \'path\': identifier\n },\n documentGroup-> {\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n documentGroupMapping[]-> {\n _id,\n name,\n thumbnail,\n parent->{...,parent->},\n \'path\': identifier.current\n },\n \'category\':contentCategory->{\n name,\n disableAds\n },\n \'issue\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.issueGroup._ref][0] {\n name,\n volume,\n \'issueNumber\': number,\n \'articleSource\': source,\n \'path\': identifier.current,\n \'publication\' : *[_type == \'publication\' && !(_id in path("drafts.**")) && is_visible == true && _id == ^.parent._ref][0] {\n name,\n \'path\': identifier.current\n },\n \'url\' : pdf.asset-> url\n }\n\n }';
|
|
14
14
|
case 'publication':
|
|
@@ -1,12 +1,450 @@
|
|
|
1
|
-
import './_commonjsHelpers-0c4b6f40.js';
|
|
1
|
+
import { c as createCommonjsModule, u as unwrapExports, a as commonjsGlobal } from './_commonjsHelpers-0c4b6f40.js';
|
|
2
2
|
import './_to-object-ded78eb9.js';
|
|
3
3
|
import './es6.string.iterator-9b2af4a5.js';
|
|
4
4
|
import './_library-528f1934.js';
|
|
5
5
|
import './_iter-detect-59409a32.js';
|
|
6
6
|
import './core.get-iterator-method-54d2e411.js';
|
|
7
7
|
import './web.dom.iterable-8956f9a5.js';
|
|
8
|
-
import './asyncToGenerator-7c654f36.js';
|
|
8
|
+
import { a as _asyncToGenerator, r as regenerator } from './asyncToGenerator-7c654f36.js';
|
|
9
9
|
import './_set-species-cede29f8.js';
|
|
10
|
-
import './index-db3bb315.js';
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { c as cookie } from './index-db3bb315.js';
|
|
11
|
+
import getQuery from './getQuery.js';
|
|
12
|
+
|
|
13
|
+
var defaultParseOptions = {
|
|
14
|
+
decodeValues: true,
|
|
15
|
+
map: false,
|
|
16
|
+
silent: false,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function isNonEmptyString(str) {
|
|
20
|
+
return typeof str === "string" && !!str.trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parseString(setCookieValue, options) {
|
|
24
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
25
|
+
var nameValue = parts.shift().split("=");
|
|
26
|
+
var name = nameValue.shift();
|
|
27
|
+
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
28
|
+
|
|
29
|
+
options = options
|
|
30
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
31
|
+
: defaultParseOptions;
|
|
32
|
+
|
|
33
|
+
var cookie = {
|
|
34
|
+
name: name, // grab everything before the first =
|
|
35
|
+
value: options.decodeValues ? decodeURIComponent(value) : value, // decode cookie value
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
parts.forEach(function (part) {
|
|
39
|
+
var sides = part.split("=");
|
|
40
|
+
var key = sides.shift().trimLeft().toLowerCase();
|
|
41
|
+
var value = sides.join("=");
|
|
42
|
+
if (key === "expires") {
|
|
43
|
+
cookie.expires = new Date(value);
|
|
44
|
+
} else if (key === "max-age") {
|
|
45
|
+
cookie.maxAge = parseInt(value, 10);
|
|
46
|
+
} else if (key === "secure") {
|
|
47
|
+
cookie.secure = true;
|
|
48
|
+
} else if (key === "httponly") {
|
|
49
|
+
cookie.httpOnly = true;
|
|
50
|
+
} else if (key === "samesite") {
|
|
51
|
+
cookie.sameSite = value;
|
|
52
|
+
} else {
|
|
53
|
+
cookie[key] = value;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return cookie;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function parse(input, options) {
|
|
61
|
+
options = options
|
|
62
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
63
|
+
: defaultParseOptions;
|
|
64
|
+
|
|
65
|
+
if (!input) {
|
|
66
|
+
if (!options.map) {
|
|
67
|
+
return [];
|
|
68
|
+
} else {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (input.headers && input.headers["set-cookie"]) {
|
|
74
|
+
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
75
|
+
input = input.headers["set-cookie"];
|
|
76
|
+
} else if (input.headers) {
|
|
77
|
+
// slow-path for other environments - see #25
|
|
78
|
+
var sch =
|
|
79
|
+
input.headers[
|
|
80
|
+
Object.keys(input.headers).find(function (key) {
|
|
81
|
+
return key.toLowerCase() === "set-cookie";
|
|
82
|
+
})
|
|
83
|
+
];
|
|
84
|
+
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
85
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
86
|
+
console.warn(
|
|
87
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
input = sch;
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(input)) {
|
|
93
|
+
input = [input];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
options = options
|
|
97
|
+
? Object.assign({}, defaultParseOptions, options)
|
|
98
|
+
: defaultParseOptions;
|
|
99
|
+
|
|
100
|
+
if (!options.map) {
|
|
101
|
+
return input.filter(isNonEmptyString).map(function (str) {
|
|
102
|
+
return parseString(str, options);
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
var cookies = {};
|
|
106
|
+
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
107
|
+
var cookie = parseString(str, options);
|
|
108
|
+
cookies[cookie.name] = cookie;
|
|
109
|
+
return cookies;
|
|
110
|
+
}, cookies);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
116
|
+
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
117
|
+
|
|
118
|
+
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
119
|
+
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
120
|
+
React Native's fetch does this for *every* header, including set-cookie.
|
|
121
|
+
|
|
122
|
+
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
123
|
+
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
124
|
+
*/
|
|
125
|
+
function splitCookiesString(cookiesString) {
|
|
126
|
+
if (Array.isArray(cookiesString)) {
|
|
127
|
+
return cookiesString;
|
|
128
|
+
}
|
|
129
|
+
if (typeof cookiesString !== "string") {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var cookiesStrings = [];
|
|
134
|
+
var pos = 0;
|
|
135
|
+
var start;
|
|
136
|
+
var ch;
|
|
137
|
+
var lastComma;
|
|
138
|
+
var nextStart;
|
|
139
|
+
var cookiesSeparatorFound;
|
|
140
|
+
|
|
141
|
+
function skipWhitespace() {
|
|
142
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
143
|
+
pos += 1;
|
|
144
|
+
}
|
|
145
|
+
return pos < cookiesString.length;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function notSpecialChar() {
|
|
149
|
+
ch = cookiesString.charAt(pos);
|
|
150
|
+
|
|
151
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
while (pos < cookiesString.length) {
|
|
155
|
+
start = pos;
|
|
156
|
+
cookiesSeparatorFound = false;
|
|
157
|
+
|
|
158
|
+
while (skipWhitespace()) {
|
|
159
|
+
ch = cookiesString.charAt(pos);
|
|
160
|
+
if (ch === ",") {
|
|
161
|
+
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
162
|
+
lastComma = pos;
|
|
163
|
+
pos += 1;
|
|
164
|
+
|
|
165
|
+
skipWhitespace();
|
|
166
|
+
nextStart = pos;
|
|
167
|
+
|
|
168
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
169
|
+
pos += 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// currently special character
|
|
173
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
174
|
+
// we found cookies separator
|
|
175
|
+
cookiesSeparatorFound = true;
|
|
176
|
+
// pos is inside the next cookie, so back up and return it.
|
|
177
|
+
pos = nextStart;
|
|
178
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
179
|
+
start = pos;
|
|
180
|
+
} else {
|
|
181
|
+
// in param ',' or param separator ';',
|
|
182
|
+
// we continue from that comma
|
|
183
|
+
pos = lastComma + 1;
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
pos += 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
191
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return cookiesStrings;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
var setCookie = parse;
|
|
199
|
+
var parse_1 = parse;
|
|
200
|
+
var parseString_1 = parseString;
|
|
201
|
+
var splitCookiesString_1 = splitCookiesString;
|
|
202
|
+
setCookie.parse = parse_1;
|
|
203
|
+
setCookie.parseString = parseString_1;
|
|
204
|
+
setCookie.splitCookiesString = splitCookiesString_1;
|
|
205
|
+
|
|
206
|
+
var dist = createCommonjsModule(function (module, exports) {
|
|
207
|
+
var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
|
|
208
|
+
__assign = Object.assign || function(t) {
|
|
209
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
210
|
+
s = arguments[i];
|
|
211
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
212
|
+
t[p] = s[p];
|
|
213
|
+
}
|
|
214
|
+
return t;
|
|
215
|
+
};
|
|
216
|
+
return __assign.apply(this, arguments);
|
|
217
|
+
};
|
|
218
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
219
|
+
exports.destroyCookie = exports.setCookie = exports.parseCookies = void 0;
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
var isBrowser = function () { return typeof window !== 'undefined'; };
|
|
223
|
+
function hasSameProperties(a, b) {
|
|
224
|
+
var aProps = Object.getOwnPropertyNames(a);
|
|
225
|
+
var bProps = Object.getOwnPropertyNames(b);
|
|
226
|
+
if (aProps.length !== bProps.length) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
for (var i = 0; i < aProps.length; i++) {
|
|
230
|
+
var propName = aProps[i];
|
|
231
|
+
if (a[propName] !== b[propName]) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Compare the cookie and return true if the cookies has equivalent
|
|
239
|
+
* options and the cookies would be overwritten in the browser storage.
|
|
240
|
+
*
|
|
241
|
+
* @param a first Cookie for comparison
|
|
242
|
+
* @param b second Cookie for comparison
|
|
243
|
+
*/
|
|
244
|
+
function areCookiesEqual(a, b) {
|
|
245
|
+
var sameSiteSame = a.sameSite === b.sameSite;
|
|
246
|
+
if (typeof a.sameSite === 'string' && typeof b.sameSite === 'string') {
|
|
247
|
+
sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
|
|
248
|
+
}
|
|
249
|
+
return (hasSameProperties(__assign(__assign({}, a), { sameSite: undefined }), __assign(__assign({}, b), { sameSite: undefined })) && sameSiteSame);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Create an instance of the Cookie interface
|
|
253
|
+
*
|
|
254
|
+
* @param name name of the Cookie
|
|
255
|
+
* @param value value of the Cookie
|
|
256
|
+
* @param options Cookie options
|
|
257
|
+
*/
|
|
258
|
+
function createCookie(name, value, options) {
|
|
259
|
+
var sameSite = options.sameSite;
|
|
260
|
+
if (sameSite === true) {
|
|
261
|
+
sameSite = 'strict';
|
|
262
|
+
}
|
|
263
|
+
if (sameSite === undefined || sameSite === false) {
|
|
264
|
+
sameSite = 'lax';
|
|
265
|
+
}
|
|
266
|
+
var cookieToSet = __assign(__assign({}, options), { sameSite: sameSite });
|
|
267
|
+
delete cookieToSet.encode;
|
|
268
|
+
return __assign({ name: name, value: value }, cookieToSet);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
*
|
|
272
|
+
* Parses cookies.
|
|
273
|
+
*
|
|
274
|
+
* @param ctx
|
|
275
|
+
* @param options
|
|
276
|
+
*/
|
|
277
|
+
function parseCookies(ctx, options) {
|
|
278
|
+
if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) {
|
|
279
|
+
return cookie.parse(ctx.req.headers.cookie, options);
|
|
280
|
+
}
|
|
281
|
+
if (isBrowser()) {
|
|
282
|
+
return cookie.parse(document.cookie, options);
|
|
283
|
+
}
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
exports.parseCookies = parseCookies;
|
|
287
|
+
/**
|
|
288
|
+
*
|
|
289
|
+
* Sets a cookie.
|
|
290
|
+
*
|
|
291
|
+
* @param ctx
|
|
292
|
+
* @param name
|
|
293
|
+
* @param value
|
|
294
|
+
* @param options
|
|
295
|
+
*/
|
|
296
|
+
function setCookie$1(ctx, name, value, options) {
|
|
297
|
+
if (ctx && ctx.res && ctx.res.getHeader && ctx.res.setHeader) {
|
|
298
|
+
var cookies = ctx.res.getHeader('Set-Cookie') || [];
|
|
299
|
+
if (typeof cookies === 'string')
|
|
300
|
+
cookies = [cookies];
|
|
301
|
+
if (typeof cookies === 'number')
|
|
302
|
+
cookies = [];
|
|
303
|
+
var parsedCookies = setCookie.parse(cookies);
|
|
304
|
+
var cookiesToSet_1 = [];
|
|
305
|
+
parsedCookies.forEach(function (parsedCookie) {
|
|
306
|
+
if (!areCookiesEqual(parsedCookie, createCookie(name, value, options))) {
|
|
307
|
+
cookiesToSet_1.push(cookie.serialize(parsedCookie.name, parsedCookie.value, __assign({}, parsedCookie)));
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
cookiesToSet_1.push(cookie.serialize(name, value, options));
|
|
311
|
+
if (!ctx.res.finished) {
|
|
312
|
+
ctx.res.setHeader('Set-Cookie', cookiesToSet_1);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (isBrowser()) {
|
|
316
|
+
if (options && options.httpOnly) {
|
|
317
|
+
throw new Error('Can not set a httpOnly cookie in the browser.');
|
|
318
|
+
}
|
|
319
|
+
document.cookie = cookie.serialize(name, value, options);
|
|
320
|
+
}
|
|
321
|
+
return {};
|
|
322
|
+
}
|
|
323
|
+
exports.setCookie = setCookie$1;
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* Destroys a cookie with a particular name.
|
|
327
|
+
*
|
|
328
|
+
* @param ctx
|
|
329
|
+
* @param name
|
|
330
|
+
* @param options
|
|
331
|
+
*/
|
|
332
|
+
function destroyCookie(ctx, name, options) {
|
|
333
|
+
var opts = __assign(__assign({}, (options || {})), { maxAge: -1 });
|
|
334
|
+
if (ctx && ctx.res && ctx.res.setHeader && ctx.res.getHeader) {
|
|
335
|
+
var cookies = ctx.res.getHeader('Set-Cookie') || [];
|
|
336
|
+
if (typeof cookies === 'string')
|
|
337
|
+
cookies = [cookies];
|
|
338
|
+
if (typeof cookies === 'number')
|
|
339
|
+
cookies = [];
|
|
340
|
+
cookies.push(cookie.serialize(name, '', opts));
|
|
341
|
+
ctx.res.setHeader('Set-Cookie', cookies);
|
|
342
|
+
}
|
|
343
|
+
if (isBrowser()) {
|
|
344
|
+
document.cookie = cookie.serialize(name, '', opts);
|
|
345
|
+
}
|
|
346
|
+
return {};
|
|
347
|
+
}
|
|
348
|
+
exports.destroyCookie = destroyCookie;
|
|
349
|
+
exports.default = {
|
|
350
|
+
set: setCookie$1,
|
|
351
|
+
get: parseCookies,
|
|
352
|
+
destroy: destroyCookie,
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
unwrapExports(dist);
|
|
358
|
+
var dist_1 = dist.destroyCookie;
|
|
359
|
+
var dist_2 = dist.setCookie;
|
|
360
|
+
var dist_3 = dist.parseCookies;
|
|
361
|
+
|
|
362
|
+
var _this = undefined;
|
|
363
|
+
|
|
364
|
+
var getRelatedArticle = function () {
|
|
365
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
|
|
366
|
+
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
367
|
+
var client = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
368
|
+
var article = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
369
|
+
var prevUrl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '/';
|
|
370
|
+
var articleCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
371
|
+
|
|
372
|
+
var taxonomyMapping, _article$url, url, content_placement, taxonomy, params, conditions, cookies, prevSlugs, relatedArticleQuery, relatedArticle;
|
|
373
|
+
|
|
374
|
+
return regenerator.wrap(function _callee$(_context) {
|
|
375
|
+
while (1) {
|
|
376
|
+
switch (_context.prev = _context.next) {
|
|
377
|
+
case 0:
|
|
378
|
+
taxonomyMapping = article.taxonomyMapping, _article$url = article.url;
|
|
379
|
+
_article$url = _article$url === undefined ? {
|
|
380
|
+
current: null
|
|
381
|
+
} : _article$url;
|
|
382
|
+
url = _article$url.current, content_placement = article.content_placement;
|
|
383
|
+
taxonomy = [];
|
|
384
|
+
//404 articles were throwing server error
|
|
385
|
+
|
|
386
|
+
if (content_placement) {
|
|
387
|
+
content_placement.forEach(function (_ref3) {
|
|
388
|
+
var path = _ref3.path,
|
|
389
|
+
_id = _ref3._id;
|
|
390
|
+
|
|
391
|
+
if (!_id || typeof _id == 'undefined') {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
var prev_url_to_check = prevUrl;
|
|
395
|
+
if (prev_url_to_check.includes('?')) {
|
|
396
|
+
prev_url_to_check = prev_url_to_check.split('?')[0];
|
|
397
|
+
}
|
|
398
|
+
if (prev_url_to_check.endsWith(path) && _id) taxonomy.push(_id);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
//404 articles were throwing server error
|
|
403
|
+
if (taxonomy.length === 0 && taxonomyMapping) {
|
|
404
|
+
taxonomyMapping.forEach(function (_ref4) {
|
|
405
|
+
var _ref = _ref4._ref;
|
|
406
|
+
|
|
407
|
+
if (_ref) {
|
|
408
|
+
taxonomy.push(_ref);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
params = {
|
|
414
|
+
url: url,
|
|
415
|
+
taxonomy: taxonomy,
|
|
416
|
+
index: articleCount
|
|
417
|
+
};
|
|
418
|
+
conditions = '';
|
|
419
|
+
|
|
420
|
+
if (ctx && url) {
|
|
421
|
+
cookies = dist_3(ctx);
|
|
422
|
+
prevSlugs = cookies['prevSlugs'];
|
|
423
|
+
|
|
424
|
+
if (!!prevSlugs) {
|
|
425
|
+
dist_2(ctx, 'prevSlugs', prevSlugs + ',"' + url + '"', {});
|
|
426
|
+
conditions = '&& !(url.current in [' + prevSlugs + '])';
|
|
427
|
+
} else dist_2(ctx, 'prevSlugs', '"' + url + '"', {});
|
|
428
|
+
}
|
|
429
|
+
relatedArticleQuery = getQuery('related', conditions, '', articleCount);
|
|
430
|
+
_context.next = 12;
|
|
431
|
+
return client.fetch(relatedArticleQuery, params);
|
|
432
|
+
|
|
433
|
+
case 12:
|
|
434
|
+
relatedArticle = _context.sent;
|
|
435
|
+
return _context.abrupt('return', relatedArticle);
|
|
436
|
+
|
|
437
|
+
case 14:
|
|
438
|
+
case 'end':
|
|
439
|
+
return _context.stop();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}, _callee, _this);
|
|
443
|
+
}));
|
|
444
|
+
|
|
445
|
+
return function getRelatedArticle() {
|
|
446
|
+
return _ref2.apply(this, arguments);
|
|
447
|
+
};
|
|
448
|
+
}();
|
|
449
|
+
|
|
450
|
+
export default getRelatedArticle;
|
package/dist/esm/index.js
CHANGED
|
@@ -154,7 +154,7 @@ export { default as KMTracker } from './KMTracker.js';
|
|
|
154
154
|
export { default as getSeriesDetail } from './getSeriesDetail.js';
|
|
155
155
|
export { default as SetCookie } from './SetCookie.js';
|
|
156
156
|
import './index-db3bb315.js';
|
|
157
|
-
export {
|
|
157
|
+
export { default as getRelatedArticle } from './getRelatedArticle.js';
|
|
158
158
|
export { default as getQuery } from './getQuery.js';
|
|
159
159
|
export { default as Auth } from './Auth.js';
|
|
160
160
|
import 'swr';
|