feedsmith 3.0.0-rc.2 → 3.0.0-rc.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/common/config.cjs +1 -0
- package/dist/common/config.js +29 -28
- package/dist/common/utils.cjs +113 -125
- package/dist/common/utils.js +111 -124
- package/dist/feeds/atom/generate/config.cjs +6 -2
- package/dist/feeds/atom/generate/config.js +5 -1
- package/dist/feeds/atom/generate/utils.cjs +45 -8
- package/dist/feeds/atom/generate/utils.js +47 -11
- package/dist/feeds/atom/parse/config.cjs +4 -70
- package/dist/feeds/atom/parse/config.js +5 -68
- package/dist/feeds/atom/parse/index.cjs +20 -3
- package/dist/feeds/atom/parse/index.js +20 -3
- package/dist/feeds/atom/parse/utils.cjs +99 -6
- package/dist/feeds/atom/parse/utils.js +96 -8
- package/dist/feeds/json/parse/utils.cjs +29 -29
- package/dist/feeds/json/parse/utils.js +30 -30
- package/dist/feeds/rdf/parse/config.cjs +14 -24
- package/dist/feeds/rdf/parse/config.js +15 -22
- package/dist/feeds/rdf/parse/index.cjs +20 -3
- package/dist/feeds/rdf/parse/index.js +20 -3
- package/dist/feeds/rss/generate/config.cjs +6 -2
- package/dist/feeds/rss/generate/config.js +5 -1
- package/dist/feeds/rss/parse/config.cjs +0 -9
- package/dist/feeds/rss/parse/config.js +2 -9
- package/dist/feeds/rss/parse/index.cjs +19 -3
- package/dist/feeds/rss/parse/index.js +19 -3
- package/dist/namespaces/atom/common/config.cjs +68 -0
- package/dist/namespaces/atom/common/config.js +65 -1
- package/dist/namespaces/rawvoice/parse/utils.cjs +1 -1
- package/dist/namespaces/rawvoice/parse/utils.js +2 -2
- package/dist/node_modules/trousse/dist/json.cjs +16 -0
- package/dist/node_modules/trousse/dist/json.js +16 -0
- package/dist/node_modules/trousse/dist/locales.cjs +15 -0
- package/dist/node_modules/trousse/dist/locales.js +15 -0
- package/dist/node_modules/trousse/dist/urls.cjs +9 -0
- package/dist/node_modules/trousse/dist/urls.js +9 -0
- package/package.json +1 -1
package/dist/common/utils.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { isNonEmptyString, isNumber, isPlainObject, isPresent } from "../node_modules/trousse/dist/is.js";
|
|
2
2
|
import { coerceBoolean, coerceNumber, coerceSingular } from "../node_modules/trousse/dist/coercions.js";
|
|
3
|
+
import { isJsonLike } from "../node_modules/trousse/dist/json.js";
|
|
3
4
|
import { decodeHTML } from "entities";
|
|
4
5
|
//#region src/common/utils.ts
|
|
5
6
|
const isNonEmptyStringOrNumber = (value) => {
|
|
6
7
|
return isNumber(value) || isNonEmptyString(value);
|
|
7
8
|
};
|
|
9
|
+
const isXmlAttributeKey = (key) => {
|
|
10
|
+
return key.charCodeAt(0) === 64;
|
|
11
|
+
};
|
|
8
12
|
const retrieveText = (value) => {
|
|
9
13
|
return value?.["#text"] ?? value;
|
|
10
14
|
};
|
|
@@ -99,7 +103,7 @@ const parseString = (value) => {
|
|
|
99
103
|
}
|
|
100
104
|
if (typeof value === "number") return value.toString();
|
|
101
105
|
};
|
|
102
|
-
const
|
|
106
|
+
const parseVerbatimString = (value) => {
|
|
103
107
|
if (typeof value === "string") {
|
|
104
108
|
if (value === "") return;
|
|
105
109
|
return value.trim() || void 0;
|
|
@@ -222,7 +226,7 @@ const detectNamespaces = (value, recursive = false) => {
|
|
|
222
226
|
if (isPlainObject(current)) for (const key in current) {
|
|
223
227
|
if (seenKeys?.has(key)) continue;
|
|
224
228
|
seenKeys?.add(key);
|
|
225
|
-
const keyWithoutAt = key
|
|
229
|
+
const keyWithoutAt = isXmlAttributeKey(key) ? key.slice(1) : key;
|
|
226
230
|
const colonIndex = keyWithoutAt.indexOf(":");
|
|
227
231
|
if (colonIndex > 0) namespaces.add(keyWithoutAt.slice(0, colonIndex));
|
|
228
232
|
if (recursive) traverse(current[key]);
|
|
@@ -265,141 +269,124 @@ const generateNamespaceAttrs = (value, namespaceUris) => {
|
|
|
265
269
|
}
|
|
266
270
|
return namespaceAttrs;
|
|
267
271
|
};
|
|
268
|
-
const
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return normalized;
|
|
272
|
+
const createNamespaceResolver = (options) => {
|
|
273
|
+
const { namespaceUris, namespacePrefixes, primaryNamespaces } = options;
|
|
274
|
+
const primaryUris = new Set(primaryNamespaces?.flatMap((key) => {
|
|
275
|
+
return namespaceUris[key]?.map((uri) => uri.toLowerCase()) ?? [];
|
|
276
|
+
}));
|
|
277
|
+
const resolveUri = (uri) => {
|
|
278
|
+
const normalized = uri.trim().toLowerCase();
|
|
279
|
+
if (primaryUris.has(normalized)) return "";
|
|
280
|
+
return namespacePrefixes[normalized];
|
|
278
281
|
};
|
|
279
|
-
const
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const declarations = {};
|
|
289
|
-
if (isPlainObject(element)) {
|
|
290
|
-
for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
|
|
291
|
-
else if (key.indexOf("@xmlns:") === 0) {
|
|
292
|
-
const prefix = key.slice(7);
|
|
293
|
-
declarations[prefix] = normalizeNamespaceUri(element[key]);
|
|
294
|
-
}
|
|
282
|
+
const seedScanLimit = 65536;
|
|
283
|
+
const findRootIndex = (document) => {
|
|
284
|
+
let index = document.indexOf("<");
|
|
285
|
+
while (index !== -1) {
|
|
286
|
+
const marker = document.charCodeAt(index + 1);
|
|
287
|
+
if (marker !== 63 && marker !== 33) return index;
|
|
288
|
+
const end = document.startsWith("<!--", index) ? document.indexOf("-->", index) : document.indexOf(">", index);
|
|
289
|
+
if (end === -1) return -1;
|
|
290
|
+
index = document.indexOf("<", end);
|
|
295
291
|
}
|
|
296
|
-
return
|
|
292
|
+
return -1;
|
|
297
293
|
};
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
if (key.charCodeAt(0) === 64) {
|
|
312
|
-
const attrName = key.slice(1);
|
|
313
|
-
return `@${normalizeWithContext(attrName, context, false)}`;
|
|
314
|
-
}
|
|
315
|
-
return normalizeWithContext(key, context, true);
|
|
316
|
-
};
|
|
317
|
-
const traverseAndNormalize = (object, parentContext = {}) => {
|
|
318
|
-
if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
|
|
319
|
-
if (!isPlainObject(object)) return object;
|
|
320
|
-
const declarations = extractNamespaceDeclarations(object);
|
|
321
|
-
let hasDeclarations = false;
|
|
322
|
-
for (const _ in declarations) {
|
|
323
|
-
hasDeclarations = true;
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
const currentContext = hasDeclarations ? {
|
|
327
|
-
...parentContext,
|
|
328
|
-
...declarations
|
|
329
|
-
} : parentContext;
|
|
330
|
-
const normalizedObject = {};
|
|
331
|
-
for (const key in object) {
|
|
332
|
-
const value = object[key];
|
|
333
|
-
if (key.indexOf("@xmlns") === 0) {
|
|
334
|
-
normalizedObject[key] = value;
|
|
335
|
-
continue;
|
|
294
|
+
return (document) => {
|
|
295
|
+
const prefixMap = /* @__PURE__ */ new Map();
|
|
296
|
+
const seededPrefixes = /* @__PURE__ */ new Set();
|
|
297
|
+
let defaultCanonical;
|
|
298
|
+
let hasRemapping = false;
|
|
299
|
+
let tagsSeen = 0;
|
|
300
|
+
const recordPrefix = (prefix, uri) => {
|
|
301
|
+
if (!prefixMap.has(prefix)) {
|
|
302
|
+
const canonical = resolveUri(uri);
|
|
303
|
+
if (canonical !== void 0) {
|
|
304
|
+
prefixMap.set(prefix, canonical);
|
|
305
|
+
if (canonical !== prefix) hasRemapping = true;
|
|
306
|
+
}
|
|
336
307
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return false;
|
|
308
|
+
};
|
|
309
|
+
if (document) {
|
|
310
|
+
const head = document.length > seedScanLimit ? document.slice(0, seedScanLimit) : document;
|
|
311
|
+
const declarationTailRegex = /([\w.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/y;
|
|
312
|
+
let index = head.indexOf("xmlns:", findRootIndex(head));
|
|
313
|
+
while (index !== -1) {
|
|
314
|
+
declarationTailRegex.lastIndex = index + 6;
|
|
315
|
+
const match = declarationTailRegex.exec(head);
|
|
316
|
+
if (match) {
|
|
317
|
+
const prefix = match[1].toLowerCase();
|
|
318
|
+
recordPrefix(prefix, match[2] ?? match[3]);
|
|
319
|
+
seededPrefixes.add(prefix);
|
|
320
|
+
}
|
|
321
|
+
index = head.indexOf("xmlns:", match ? declarationTailRegex.lastIndex : index + 6);
|
|
352
322
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const normalizedUri = normalizeNamespaceUri(value[key]);
|
|
363
|
-
const standardPrefix = namespacePrefixes[normalizedUri];
|
|
364
|
-
if (standardPrefix) {
|
|
365
|
-
if (primaryNamespaceUris?.includes(normalizedUri)) return true;
|
|
366
|
-
if (standardPrefix !== prefix) return true;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
continue;
|
|
323
|
+
}
|
|
324
|
+
const recordDeclaration = (rawAttrName, value) => {
|
|
325
|
+
const firstCharCode = rawAttrName.charCodeAt(0);
|
|
326
|
+
if (firstCharCode !== 120 && firstCharCode !== 88 || typeof value !== "string") return;
|
|
327
|
+
const attrName = rawAttrName.toLowerCase();
|
|
328
|
+
if (attrName === "xmlns") {
|
|
329
|
+
if (tagsSeen === 1 && defaultCanonical === void 0) {
|
|
330
|
+
defaultCanonical = resolveUri(value);
|
|
331
|
+
if (defaultCanonical) hasRemapping = true;
|
|
370
332
|
}
|
|
371
|
-
|
|
372
|
-
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (attrName.startsWith("xmlns:")) {
|
|
336
|
+
const prefix = attrName.slice(6);
|
|
337
|
+
if (seededPrefixes.delete(prefix)) prefixMap.delete(prefix);
|
|
338
|
+
recordPrefix(prefix, value);
|
|
373
339
|
}
|
|
374
|
-
return false;
|
|
375
340
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
341
|
+
const transformName = (name, useDefault) => {
|
|
342
|
+
const lowered = name.toLowerCase();
|
|
343
|
+
if (!hasRemapping) return lowered;
|
|
344
|
+
const colonIndex = lowered.indexOf(":");
|
|
345
|
+
if (colonIndex === -1) {
|
|
346
|
+
if (useDefault && defaultCanonical) return `${defaultCanonical}:${lowered}`;
|
|
347
|
+
return lowered;
|
|
348
|
+
}
|
|
349
|
+
const prefix = lowered.slice(0, colonIndex);
|
|
350
|
+
if (prefix === "xmlns" || prefix === "xml") return lowered;
|
|
351
|
+
const canonical = prefixMap.get(prefix);
|
|
352
|
+
if (canonical === void 0) return lowered;
|
|
353
|
+
const local = lowered.slice(colonIndex + 1);
|
|
354
|
+
return canonical === "" ? local : `${canonical}:${local}`;
|
|
355
|
+
};
|
|
356
|
+
const transformTagName = (name) => {
|
|
357
|
+
tagsSeen++;
|
|
358
|
+
return transformName(name, true);
|
|
359
|
+
};
|
|
360
|
+
const transformAttributeName = (name) => `@${transformName(name.slice(1), false)}`;
|
|
361
|
+
const attributeValueProcessor = (attrName, value) => {
|
|
362
|
+
recordDeclaration(attrName, value);
|
|
363
|
+
return value;
|
|
364
|
+
};
|
|
365
|
+
const updateTag = (tagName) => {
|
|
366
|
+
if (!hasRemapping) return tagName;
|
|
367
|
+
const colonIndex = tagName.indexOf(":");
|
|
368
|
+
if (colonIndex === -1) return defaultCanonical ? `${defaultCanonical}:${tagName}` : tagName;
|
|
369
|
+
const prefix = tagName.slice(0, colonIndex);
|
|
370
|
+
const canonical = prefixMap.get(prefix);
|
|
371
|
+
if (canonical === void 0 || canonical === prefix) return tagName;
|
|
372
|
+
const local = tagName.slice(colonIndex + 1);
|
|
373
|
+
return canonical === "" ? local : `${canonical}:${local}`;
|
|
374
|
+
};
|
|
375
|
+
return {
|
|
376
|
+
transformTagName,
|
|
377
|
+
transformAttributeName,
|
|
378
|
+
attributeValueProcessor,
|
|
379
|
+
updateTag
|
|
380
|
+
};
|
|
389
381
|
};
|
|
390
|
-
return normalizeRoot;
|
|
391
382
|
};
|
|
392
|
-
const startsWithBraceRegex = /^\s*\{/;
|
|
393
|
-
const endsWithBraceRegex = /\}\s*$/;
|
|
394
383
|
const parseJsonObject = (value) => {
|
|
395
384
|
if (isPlainObject(value)) return value;
|
|
396
|
-
if (!isNonEmptyString(value) || value
|
|
397
|
-
const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
|
|
398
|
-
const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
|
|
399
|
-
if (!startsWithBrace || !endsWithBrace) return;
|
|
385
|
+
if (!isNonEmptyString(value) || !isJsonLike(value)) return;
|
|
400
386
|
try {
|
|
401
|
-
|
|
387
|
+
const parsed = JSON.parse(value);
|
|
388
|
+
if (isPlainObject(parsed)) return parsed;
|
|
402
389
|
} catch {}
|
|
403
390
|
};
|
|
404
391
|
//#endregion
|
|
405
|
-
export {
|
|
392
|
+
export { createNamespaceResolver, detectNamespaces, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateTextOrCdataString, generateXml, generateXmlStylesheet, generateYesNoBoolean, hasEntities, isNonEmptyStringOrNumber, isXmlAttributeKey, limitArray, parseArray, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseVerbatimString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
const require_config = require("../../../common/config.cjs");
|
|
1
|
+
const require_config = require("../../../namespaces/atom/common/config.cjs");
|
|
2
|
+
const require_config$1 = require("../../../common/config.cjs");
|
|
2
3
|
//#region src/feeds/atom/generate/config.ts
|
|
3
|
-
const builder = new (require("fast-xml-parser")).XMLBuilder({
|
|
4
|
+
const builder = new (require("fast-xml-parser")).XMLBuilder({
|
|
5
|
+
...require_config$1.builderConfig,
|
|
6
|
+
stopNodes: require_config.textConstructs.map((element) => `..${element}[type=xhtml]`)
|
|
7
|
+
});
|
|
4
8
|
//#endregion
|
|
5
9
|
exports.builder = builder;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { textConstructs } from "../../../namespaces/atom/common/config.js";
|
|
1
2
|
import { builderConfig } from "../../../common/config.js";
|
|
2
3
|
import { XMLBuilder } from "fast-xml-parser";
|
|
3
4
|
//#region src/feeds/atom/generate/config.ts
|
|
4
|
-
const builder = new XMLBuilder({
|
|
5
|
+
const builder = new XMLBuilder({
|
|
6
|
+
...builderConfig,
|
|
7
|
+
stopNodes: textConstructs.map((element) => `..${element}[type=xhtml]`)
|
|
8
|
+
});
|
|
5
9
|
//#endregion
|
|
6
10
|
export { builder };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_is = require("../../../node_modules/trousse/dist/is.cjs");
|
|
2
|
+
const require_locales = require("../../../node_modules/trousse/dist/locales.cjs");
|
|
2
3
|
const require_config = require("../../../common/config.cjs");
|
|
3
4
|
const require_utils = require("../../../common/utils.cjs");
|
|
4
5
|
const require_utils$1 = require("../../../namespaces/admin/generate/utils.cjs");
|
|
@@ -23,26 +24,61 @@ const require_utils$19 = require("../../../namespaces/trackback/generate/utils.c
|
|
|
23
24
|
const require_utils$20 = require("../../../namespaces/wfw/generate/utils.cjs");
|
|
24
25
|
const require_utils$21 = require("../../../namespaces/xml/generate/utils.cjs");
|
|
25
26
|
const require_utils$22 = require("../../../namespaces/yt/generate/utils.cjs");
|
|
27
|
+
let fast_xml_parser = require("fast-xml-parser");
|
|
26
28
|
//#region src/feeds/atom/generate/utils.ts
|
|
27
29
|
const createNamespaceSetter = (prefix) => {
|
|
28
30
|
return (key) => prefix ? `${prefix}${key}` : key;
|
|
29
31
|
};
|
|
32
|
+
const nonXmlEntityRegex = /&(?!(?:amp|lt|gt|quot|apos);|#\d+;|#x[0-9a-fA-F]+;)[^;\s&<]+;/;
|
|
33
|
+
const generateXhtmlValue = (value) => {
|
|
34
|
+
if (!require_is.isNonEmptyString(value)) return;
|
|
35
|
+
const wrapped = `<div xmlns="http://www.w3.org/1999/xhtml">${value.trim().replace(/\r/g, " ")}</div>`;
|
|
36
|
+
if (fast_xml_parser.XMLValidator.validate(wrapped) !== true || nonXmlEntityRegex.test(wrapped)) return;
|
|
37
|
+
return { "#text": `${wrapped}\n` };
|
|
38
|
+
};
|
|
39
|
+
const escapeStopNodeAttributes = (value) => {
|
|
40
|
+
if (value["@type"] !== "xhtml") return value;
|
|
41
|
+
const escaped = {};
|
|
42
|
+
for (const key in value) {
|
|
43
|
+
const attribute = value[key];
|
|
44
|
+
escaped[key] = require_utils.isXmlAttributeKey(key) && typeof attribute === "string" ? require_locales.escapeHtml(attribute) : attribute;
|
|
45
|
+
}
|
|
46
|
+
return escaped;
|
|
47
|
+
};
|
|
48
|
+
const generateTypedText = (value, rawType) => {
|
|
49
|
+
const type = require_utils.generatePlainString(rawType);
|
|
50
|
+
if (type !== "xhtml") return {
|
|
51
|
+
...require_utils.generateTextOrCdataString(value),
|
|
52
|
+
"@type": type
|
|
53
|
+
};
|
|
54
|
+
const xhtml = generateXhtmlValue(value);
|
|
55
|
+
if (xhtml || !require_is.isNonEmptyString(value)) return {
|
|
56
|
+
...xhtml,
|
|
57
|
+
"@type": "xhtml"
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...require_utils.generateTextOrCdataString(value),
|
|
61
|
+
"@type": "html"
|
|
62
|
+
};
|
|
63
|
+
};
|
|
30
64
|
const generateText = (text) => {
|
|
31
65
|
if (!require_is.isPlainObject(text)) return;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
const typed = generateTypedText(text.value, text.type);
|
|
67
|
+
if (!typed?.["#text"] && !typed?.["#cdata"]) return;
|
|
68
|
+
const value = {
|
|
69
|
+
...typed,
|
|
35
70
|
...require_utils$21.generateItemOrFeed(text.xml)
|
|
36
|
-
}
|
|
71
|
+
};
|
|
72
|
+
return require_utils.trimObject(escapeStopNodeAttributes(value));
|
|
37
73
|
};
|
|
38
74
|
const generateContent = (content) => {
|
|
39
75
|
if (!require_is.isPlainObject(content)) return;
|
|
40
|
-
|
|
41
|
-
...
|
|
42
|
-
"@type": require_utils.generatePlainString(content.type),
|
|
76
|
+
const value = {
|
|
77
|
+
...generateTypedText(content.value, content.type),
|
|
43
78
|
"@src": require_utils.generatePlainString(content.src),
|
|
44
79
|
...require_utils$21.generateItemOrFeed(content.xml)
|
|
45
|
-
}
|
|
80
|
+
};
|
|
81
|
+
return require_utils.trimObject(escapeStopNodeAttributes(value));
|
|
46
82
|
};
|
|
47
83
|
const generateLink = (link) => {
|
|
48
84
|
if (!require_is.isPlainObject(link)) return;
|
|
@@ -201,3 +237,4 @@ exports.generateLink = generateLink;
|
|
|
201
237
|
exports.generatePerson = generatePerson;
|
|
202
238
|
exports.generateSource = generateSource;
|
|
203
239
|
exports.generateText = generateText;
|
|
240
|
+
exports.generateXhtmlValue = generateXhtmlValue;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { isPlainObject } from "../../../node_modules/trousse/dist/is.js";
|
|
1
|
+
import { isNonEmptyString, isPlainObject } from "../../../node_modules/trousse/dist/is.js";
|
|
2
|
+
import { escapeHtml } from "../../../node_modules/trousse/dist/locales.js";
|
|
2
3
|
import { namespaceUris } from "../../../common/config.js";
|
|
3
|
-
import { generateCdataString, generateNamespaceAttrs, generateNumber, generatePlainString, generateRfc3339Date, generateTextOrCdataString, trimArray, trimObject } from "../../../common/utils.js";
|
|
4
|
+
import { generateCdataString, generateNamespaceAttrs, generateNumber, generatePlainString, generateRfc3339Date, generateTextOrCdataString, isXmlAttributeKey, trimArray, trimObject } from "../../../common/utils.js";
|
|
4
5
|
import { generateFeed as generateFeed$1 } from "../../../namespaces/admin/generate/utils.js";
|
|
5
6
|
import { generateEntry as generateEntry$1 } from "../../../namespaces/app/generate/utils.js";
|
|
6
7
|
import { generateAuthor, generateEntry as generateEntry$2 } from "../../../namespaces/arxiv/generate/utils.js";
|
|
@@ -23,26 +24,61 @@ import { generateItem as generateItem$6 } from "../../../namespaces/trackback/ge
|
|
|
23
24
|
import { generateItem as generateItem$7 } from "../../../namespaces/wfw/generate/utils.js";
|
|
24
25
|
import { generateItemOrFeed as generateItemOrFeed$7 } from "../../../namespaces/xml/generate/utils.js";
|
|
25
26
|
import { generateFeed as generateFeed$7, generateItem as generateItem$8 } from "../../../namespaces/yt/generate/utils.js";
|
|
27
|
+
import { XMLValidator } from "fast-xml-parser";
|
|
26
28
|
//#region src/feeds/atom/generate/utils.ts
|
|
27
29
|
const createNamespaceSetter = (prefix) => {
|
|
28
30
|
return (key) => prefix ? `${prefix}${key}` : key;
|
|
29
31
|
};
|
|
32
|
+
const nonXmlEntityRegex = /&(?!(?:amp|lt|gt|quot|apos);|#\d+;|#x[0-9a-fA-F]+;)[^;\s&<]+;/;
|
|
33
|
+
const generateXhtmlValue = (value) => {
|
|
34
|
+
if (!isNonEmptyString(value)) return;
|
|
35
|
+
const wrapped = `<div xmlns="http://www.w3.org/1999/xhtml">${value.trim().replace(/\r/g, " ")}</div>`;
|
|
36
|
+
if (XMLValidator.validate(wrapped) !== true || nonXmlEntityRegex.test(wrapped)) return;
|
|
37
|
+
return { "#text": `${wrapped}\n` };
|
|
38
|
+
};
|
|
39
|
+
const escapeStopNodeAttributes = (value) => {
|
|
40
|
+
if (value["@type"] !== "xhtml") return value;
|
|
41
|
+
const escaped = {};
|
|
42
|
+
for (const key in value) {
|
|
43
|
+
const attribute = value[key];
|
|
44
|
+
escaped[key] = isXmlAttributeKey(key) && typeof attribute === "string" ? escapeHtml(attribute) : attribute;
|
|
45
|
+
}
|
|
46
|
+
return escaped;
|
|
47
|
+
};
|
|
48
|
+
const generateTypedText = (value, rawType) => {
|
|
49
|
+
const type = generatePlainString(rawType);
|
|
50
|
+
if (type !== "xhtml") return {
|
|
51
|
+
...generateTextOrCdataString(value),
|
|
52
|
+
"@type": type
|
|
53
|
+
};
|
|
54
|
+
const xhtml = generateXhtmlValue(value);
|
|
55
|
+
if (xhtml || !isNonEmptyString(value)) return {
|
|
56
|
+
...xhtml,
|
|
57
|
+
"@type": "xhtml"
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
...generateTextOrCdataString(value),
|
|
61
|
+
"@type": "html"
|
|
62
|
+
};
|
|
63
|
+
};
|
|
30
64
|
const generateText = (text) => {
|
|
31
65
|
if (!isPlainObject(text)) return;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
66
|
+
const typed = generateTypedText(text.value, text.type);
|
|
67
|
+
if (!typed?.["#text"] && !typed?.["#cdata"]) return;
|
|
68
|
+
const value = {
|
|
69
|
+
...typed,
|
|
35
70
|
...generateItemOrFeed$7(text.xml)
|
|
36
|
-
}
|
|
71
|
+
};
|
|
72
|
+
return trimObject(escapeStopNodeAttributes(value));
|
|
37
73
|
};
|
|
38
74
|
const generateContent = (content) => {
|
|
39
75
|
if (!isPlainObject(content)) return;
|
|
40
|
-
|
|
41
|
-
...
|
|
42
|
-
"@type": generatePlainString(content.type),
|
|
76
|
+
const value = {
|
|
77
|
+
...generateTypedText(content.value, content.type),
|
|
43
78
|
"@src": generatePlainString(content.src),
|
|
44
79
|
...generateItemOrFeed$7(content.xml)
|
|
45
|
-
}
|
|
80
|
+
};
|
|
81
|
+
return trimObject(escapeStopNodeAttributes(value));
|
|
46
82
|
};
|
|
47
83
|
const generateLink = (link) => {
|
|
48
84
|
if (!isPlainObject(link)) return;
|
|
@@ -191,4 +227,4 @@ const generateFeed = (feed, options) => {
|
|
|
191
227
|
} };
|
|
192
228
|
};
|
|
193
229
|
//#endregion
|
|
194
|
-
export { createNamespaceSetter, generateCategory, generateContent, generateEntry, generateFeed, generateGenerator, generateLink, generatePerson, generateSource, generateText };
|
|
230
|
+
export { createNamespaceSetter, generateCategory, generateContent, generateEntry, generateFeed, generateGenerator, generateLink, generatePerson, generateSource, generateText, generateXhtmlValue };
|
|
@@ -1,75 +1,9 @@
|
|
|
1
|
-
const require_config = require("../../../common/config.cjs");
|
|
2
|
-
const require_utils = require("../../../common/utils.cjs");
|
|
3
|
-
let fast_xml_parser = require("fast-xml-parser");
|
|
1
|
+
const require_config = require("../../../namespaces/atom/common/config.cjs");
|
|
4
2
|
//#region src/feeds/atom/parse/config.ts
|
|
5
3
|
const stopNodes = [
|
|
6
|
-
...
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"feed.author.url",
|
|
10
|
-
"feed.author.email",
|
|
11
|
-
"feed.category",
|
|
12
|
-
"feed.contributor.name",
|
|
13
|
-
"feed.contributor.uri",
|
|
14
|
-
"feed.contributor.url",
|
|
15
|
-
"feed.contributor.email",
|
|
16
|
-
"feed.generator",
|
|
17
|
-
"feed.icon",
|
|
18
|
-
"feed.id",
|
|
19
|
-
"feed.link",
|
|
20
|
-
"feed.logo",
|
|
21
|
-
"feed.rights",
|
|
22
|
-
"feed.subtitle",
|
|
23
|
-
"feed.tagline",
|
|
24
|
-
"feed.title",
|
|
25
|
-
"feed.updated",
|
|
26
|
-
"feed.modified",
|
|
27
|
-
"feed.entry.author.name",
|
|
28
|
-
"feed.entry.author.uri",
|
|
29
|
-
"feed.entry.author.url",
|
|
30
|
-
"feed.entry.author.email",
|
|
31
|
-
"feed.entry.category",
|
|
32
|
-
"feed.entry.content",
|
|
33
|
-
"feed.entry.contributor.name",
|
|
34
|
-
"feed.entry.contributor.uri",
|
|
35
|
-
"feed.entry.contributor.url",
|
|
36
|
-
"feed.entry.contributor.email",
|
|
37
|
-
"feed.entry.id",
|
|
38
|
-
"feed.entry.link",
|
|
39
|
-
"feed.entry.published",
|
|
40
|
-
"feed.entry.issued",
|
|
41
|
-
"feed.entry.created",
|
|
42
|
-
"feed.entry.rights",
|
|
43
|
-
"feed.entry.source.author.name",
|
|
44
|
-
"feed.entry.source.author.uri",
|
|
45
|
-
"feed.entry.source.author.url",
|
|
46
|
-
"feed.entry.source.author.email",
|
|
47
|
-
"feed.entry.source.category",
|
|
48
|
-
"feed.entry.source.contributor.name",
|
|
49
|
-
"feed.entry.source.contributor.uri",
|
|
50
|
-
"feed.entry.source.contributor.url",
|
|
51
|
-
"feed.entry.source.contributor.email",
|
|
52
|
-
"feed.entry.source.generator",
|
|
53
|
-
"feed.entry.source.icon",
|
|
54
|
-
"feed.entry.source.id",
|
|
55
|
-
"feed.entry.source.link",
|
|
56
|
-
"feed.entry.source.logo",
|
|
57
|
-
"feed.entry.source.rights",
|
|
58
|
-
"feed.entry.source.subtitle",
|
|
59
|
-
"feed.entry.source.title",
|
|
60
|
-
"feed.entry.source.updated",
|
|
61
|
-
"feed.entry.source.modified",
|
|
62
|
-
"feed.entry.summary",
|
|
63
|
-
"feed.entry.title",
|
|
64
|
-
"feed.entry.updated",
|
|
65
|
-
"feed.entry.modified"
|
|
4
|
+
...require("../../../common/config.cjs").namespaceStopNodes,
|
|
5
|
+
...require_config.feedPaths.map((path) => `feed.${path}`),
|
|
6
|
+
...require_config.entryPaths.map((path) => `feed.entry.${path}`)
|
|
66
7
|
];
|
|
67
|
-
const parser = new fast_xml_parser.XMLParser({
|
|
68
|
-
...require_config.parserConfig,
|
|
69
|
-
stopNodes
|
|
70
|
-
});
|
|
71
|
-
const normalizeNamespaces = require_utils.createNamespaceNormalizator(require_config.namespaceUris, require_config.namespacePrefixes, ["atom"]);
|
|
72
8
|
//#endregion
|
|
73
|
-
exports.normalizeNamespaces = normalizeNamespaces;
|
|
74
|
-
exports.parser = parser;
|
|
75
9
|
exports.stopNodes = stopNodes;
|
|
@@ -1,73 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { XMLParser } from "fast-xml-parser";
|
|
1
|
+
import { entryPaths, feedPaths } from "../../../namespaces/atom/common/config.js";
|
|
2
|
+
import { namespaceStopNodes } from "../../../common/config.js";
|
|
4
3
|
//#region src/feeds/atom/parse/config.ts
|
|
5
4
|
const stopNodes = [
|
|
6
5
|
...namespaceStopNodes,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"feed.author.url",
|
|
10
|
-
"feed.author.email",
|
|
11
|
-
"feed.category",
|
|
12
|
-
"feed.contributor.name",
|
|
13
|
-
"feed.contributor.uri",
|
|
14
|
-
"feed.contributor.url",
|
|
15
|
-
"feed.contributor.email",
|
|
16
|
-
"feed.generator",
|
|
17
|
-
"feed.icon",
|
|
18
|
-
"feed.id",
|
|
19
|
-
"feed.link",
|
|
20
|
-
"feed.logo",
|
|
21
|
-
"feed.rights",
|
|
22
|
-
"feed.subtitle",
|
|
23
|
-
"feed.tagline",
|
|
24
|
-
"feed.title",
|
|
25
|
-
"feed.updated",
|
|
26
|
-
"feed.modified",
|
|
27
|
-
"feed.entry.author.name",
|
|
28
|
-
"feed.entry.author.uri",
|
|
29
|
-
"feed.entry.author.url",
|
|
30
|
-
"feed.entry.author.email",
|
|
31
|
-
"feed.entry.category",
|
|
32
|
-
"feed.entry.content",
|
|
33
|
-
"feed.entry.contributor.name",
|
|
34
|
-
"feed.entry.contributor.uri",
|
|
35
|
-
"feed.entry.contributor.url",
|
|
36
|
-
"feed.entry.contributor.email",
|
|
37
|
-
"feed.entry.id",
|
|
38
|
-
"feed.entry.link",
|
|
39
|
-
"feed.entry.published",
|
|
40
|
-
"feed.entry.issued",
|
|
41
|
-
"feed.entry.created",
|
|
42
|
-
"feed.entry.rights",
|
|
43
|
-
"feed.entry.source.author.name",
|
|
44
|
-
"feed.entry.source.author.uri",
|
|
45
|
-
"feed.entry.source.author.url",
|
|
46
|
-
"feed.entry.source.author.email",
|
|
47
|
-
"feed.entry.source.category",
|
|
48
|
-
"feed.entry.source.contributor.name",
|
|
49
|
-
"feed.entry.source.contributor.uri",
|
|
50
|
-
"feed.entry.source.contributor.url",
|
|
51
|
-
"feed.entry.source.contributor.email",
|
|
52
|
-
"feed.entry.source.generator",
|
|
53
|
-
"feed.entry.source.icon",
|
|
54
|
-
"feed.entry.source.id",
|
|
55
|
-
"feed.entry.source.link",
|
|
56
|
-
"feed.entry.source.logo",
|
|
57
|
-
"feed.entry.source.rights",
|
|
58
|
-
"feed.entry.source.subtitle",
|
|
59
|
-
"feed.entry.source.title",
|
|
60
|
-
"feed.entry.source.updated",
|
|
61
|
-
"feed.entry.source.modified",
|
|
62
|
-
"feed.entry.summary",
|
|
63
|
-
"feed.entry.title",
|
|
64
|
-
"feed.entry.updated",
|
|
65
|
-
"feed.entry.modified"
|
|
6
|
+
...feedPaths.map((path) => `feed.${path}`),
|
|
7
|
+
...entryPaths.map((path) => `feed.entry.${path}`)
|
|
66
8
|
];
|
|
67
|
-
const parser = new XMLParser({
|
|
68
|
-
...parserConfig,
|
|
69
|
-
stopNodes
|
|
70
|
-
});
|
|
71
|
-
const normalizeNamespaces = createNamespaceNormalizator(namespaceUris, namespacePrefixes, ["atom"]);
|
|
72
9
|
//#endregion
|
|
73
|
-
export {
|
|
10
|
+
export { stopNodes };
|