feedkeeper 0.47.1 → 0.47.2
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 +1 -1
- package/server/dist/feeds/feedParser.js +50 -12
- package/server/package.json +1 -1
package/package.json
CHANGED
|
@@ -234,7 +234,12 @@ function extractMediaImageUrl(source) {
|
|
|
234
234
|
const url = mediaAttribute(entry, "url");
|
|
235
235
|
const medium = mediaAttribute(entry, "medium");
|
|
236
236
|
const type = mediaAttribute(entry, "type");
|
|
237
|
-
|
|
237
|
+
const isImageType = typeof type === "string" && type.toLowerCase().startsWith("image/");
|
|
238
|
+
const isNonImageType = typeof type === "string" && type.trim() !== "" && !isImageType;
|
|
239
|
+
const isNonImageMedium = typeof medium === "string" && medium.trim() !== "" && medium.toLowerCase() !== "image";
|
|
240
|
+
if (isNonImageType || isNonImageMedium)
|
|
241
|
+
continue;
|
|
242
|
+
if (isValidImageUrl(url) && (medium === "image" || !medium || isImageType)) {
|
|
238
243
|
return cleanImageUrl(url);
|
|
239
244
|
}
|
|
240
245
|
}
|
|
@@ -423,6 +428,34 @@ function extractXmlArtworkUrl(parsed) {
|
|
|
423
428
|
return parsed.icon.trim();
|
|
424
429
|
return undefined;
|
|
425
430
|
}
|
|
431
|
+
function extractXmlMediaDescription(item) {
|
|
432
|
+
const direct = asNonEmptyString(item["media:description"]);
|
|
433
|
+
if (direct)
|
|
434
|
+
return direct;
|
|
435
|
+
const mediaGroup = item.mediaGroup ?? item["media:group"];
|
|
436
|
+
if (mediaGroup) {
|
|
437
|
+
for (const group of asMediaEntries(mediaGroup)) {
|
|
438
|
+
if (!isRecord(group))
|
|
439
|
+
continue;
|
|
440
|
+
const grouped = asNonEmptyString(group["media:description"] ?? group.mediaDescription);
|
|
441
|
+
if (grouped)
|
|
442
|
+
return grouped;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
function escapePlainDescriptionHtml(text) {
|
|
448
|
+
const escaped = text
|
|
449
|
+
.replace(/&/g, "&")
|
|
450
|
+
.replace(/</g, "<")
|
|
451
|
+
.replace(/>/g, ">")
|
|
452
|
+
.replace(/"/g, """);
|
|
453
|
+
return escaped
|
|
454
|
+
.split(/\n{2,}/)
|
|
455
|
+
.map((block) => `<p>${block.trim().replace(/\n/g, "<br>")}</p>`)
|
|
456
|
+
.filter((block) => block !== "<p></p>")
|
|
457
|
+
.join("");
|
|
458
|
+
}
|
|
426
459
|
export async function parseFeedBody(body) {
|
|
427
460
|
if (body.trimStart().startsWith("{")) {
|
|
428
461
|
return parseJsonFeed(body);
|
|
@@ -445,17 +478,22 @@ export async function parseFeedBody(body) {
|
|
|
445
478
|
icons,
|
|
446
479
|
logos,
|
|
447
480
|
artworkUrl,
|
|
448
|
-
items: parsed.items.map((item) =>
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
481
|
+
items: parsed.items.map((item) => {
|
|
482
|
+
const mediaDescription = extractXmlMediaDescription(item);
|
|
483
|
+
const rawSnippet = item.contentSnippet ?? item.content ?? mediaDescription;
|
|
484
|
+
const rawHtml = item.contentEncoded ?? item["content:encoded"] ?? item.content ?? null;
|
|
485
|
+
return {
|
|
486
|
+
guid: itemGuid(item),
|
|
487
|
+
title: plainTitle(item.title),
|
|
488
|
+
link: itemLink(item),
|
|
489
|
+
contentSnippet: decodeEntities(rawSnippet) ?? undefined,
|
|
490
|
+
contentHtml: rawHtml ?? (mediaDescription ? escapePlainDescriptionHtml(mediaDescription) : null),
|
|
491
|
+
publishedAt: normalizePublishedAt(item.isoDate ?? item.pubDate) ?? undefined,
|
|
492
|
+
imageUrl: extractXmlImageUrl(item),
|
|
493
|
+
authors: [item.creator, item.author],
|
|
494
|
+
...extractXmlMedia(item),
|
|
495
|
+
};
|
|
496
|
+
}),
|
|
459
497
|
};
|
|
460
498
|
}
|
|
461
499
|
function isYouTubeUrl(rawUrl) {
|