feedkeeper 0.47.1 → 0.47.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/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,48 @@ function extractXmlArtworkUrl(parsed) {
|
|
|
423
428
|
return parsed.icon.trim();
|
|
424
429
|
return undefined;
|
|
425
430
|
}
|
|
431
|
+
function asMediaText(value) {
|
|
432
|
+
if (Array.isArray(value)) {
|
|
433
|
+
for (const entry of value) {
|
|
434
|
+
const found = asMediaText(entry);
|
|
435
|
+
if (found)
|
|
436
|
+
return found;
|
|
437
|
+
}
|
|
438
|
+
return undefined;
|
|
439
|
+
}
|
|
440
|
+
if (isRecord(value) && typeof value._ === "string") {
|
|
441
|
+
return asNonEmptyString(value._) ?? undefined;
|
|
442
|
+
}
|
|
443
|
+
return asNonEmptyString(value) ?? undefined;
|
|
444
|
+
}
|
|
445
|
+
function extractXmlMediaDescription(item) {
|
|
446
|
+
const direct = asMediaText(item["media:description"]);
|
|
447
|
+
if (direct)
|
|
448
|
+
return direct;
|
|
449
|
+
const mediaGroup = item.mediaGroup ?? item["media:group"];
|
|
450
|
+
if (mediaGroup) {
|
|
451
|
+
for (const group of asMediaEntries(mediaGroup)) {
|
|
452
|
+
if (!isRecord(group))
|
|
453
|
+
continue;
|
|
454
|
+
const grouped = asMediaText(group["media:description"] ?? group.mediaDescription);
|
|
455
|
+
if (grouped)
|
|
456
|
+
return grouped;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
function escapePlainDescriptionHtml(text) {
|
|
462
|
+
const escaped = text
|
|
463
|
+
.replace(/&/g, "&")
|
|
464
|
+
.replace(/</g, "<")
|
|
465
|
+
.replace(/>/g, ">")
|
|
466
|
+
.replace(/"/g, """);
|
|
467
|
+
return escaped
|
|
468
|
+
.split(/\n{2,}/)
|
|
469
|
+
.map((block) => `<p>${block.trim().replace(/\n/g, "<br>")}</p>`)
|
|
470
|
+
.filter((block) => block !== "<p></p>")
|
|
471
|
+
.join("");
|
|
472
|
+
}
|
|
426
473
|
export async function parseFeedBody(body) {
|
|
427
474
|
if (body.trimStart().startsWith("{")) {
|
|
428
475
|
return parseJsonFeed(body);
|
|
@@ -445,17 +492,22 @@ export async function parseFeedBody(body) {
|
|
|
445
492
|
icons,
|
|
446
493
|
logos,
|
|
447
494
|
artworkUrl,
|
|
448
|
-
items: parsed.items.map((item) =>
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
495
|
+
items: parsed.items.map((item) => {
|
|
496
|
+
const mediaDescription = extractXmlMediaDescription(item);
|
|
497
|
+
const rawSnippet = item.contentSnippet ?? item.content ?? mediaDescription;
|
|
498
|
+
const rawHtml = item.contentEncoded ?? item["content:encoded"] ?? item.content ?? null;
|
|
499
|
+
return {
|
|
500
|
+
guid: itemGuid(item),
|
|
501
|
+
title: plainTitle(item.title),
|
|
502
|
+
link: itemLink(item),
|
|
503
|
+
contentSnippet: decodeEntities(rawSnippet) ?? undefined,
|
|
504
|
+
contentHtml: rawHtml ?? (mediaDescription ? escapePlainDescriptionHtml(mediaDescription) : null),
|
|
505
|
+
publishedAt: normalizePublishedAt(item.isoDate ?? item.pubDate) ?? undefined,
|
|
506
|
+
imageUrl: extractXmlImageUrl(item),
|
|
507
|
+
authors: [item.creator, item.author],
|
|
508
|
+
...extractXmlMedia(item),
|
|
509
|
+
};
|
|
510
|
+
}),
|
|
459
511
|
};
|
|
460
512
|
}
|
|
461
513
|
function isYouTubeUrl(rawUrl) {
|
|
@@ -220,7 +220,8 @@ export function upsertItems(feedId, items) {
|
|
|
220
220
|
// a feed that alternates between two variants would change the content on every poll.
|
|
221
221
|
const keptPrevious = retained !== null && next !== retained;
|
|
222
222
|
const nextSnippet = keptPrevious ? null : row.contentSnippet ?? null;
|
|
223
|
-
const
|
|
223
|
+
const previousImageIsLegacyYouTubeSwf = Boolean(previous?.image_url && /^https?:\/\/(?:www\.)?youtube\.com\/v\//i.test(previous.image_url));
|
|
224
|
+
const reusablePreviousImage = previous?.image_url && !isAvatarImageUrl(previous.image_url) && !previousImageIsLegacyYouTubeSwf ? previous.image_url : null;
|
|
224
225
|
const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? reusablePreviousImage ?? row.imageUrl ?? null;
|
|
225
226
|
if (previous) {
|
|
226
227
|
const changed = (row.title !== undefined && row.title !== previous.title) ||
|