feedkeeper 0.42.4 → 0.42.5

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feedkeeper",
3
- "version": "0.42.4",
3
+ "version": "0.42.5",
4
4
  "description": "A lightweight, self-hosted RSS reader and remote MCP server for your news, blogs, and AI workflows.",
5
5
  "keywords": [
6
6
  "rss",
@@ -0,0 +1,5 @@
1
+ -- Clear small user/org avatars stored as hero images (e.g. GitHub release/commit/activity Atom feeds).
2
+ UPDATE items
3
+ SET image_url = NULL
4
+ WHERE image_url LIKE 'https://avatars.githubusercontent.com/%'
5
+ OR image_url LIKE 'http://avatars.githubusercontent.com/%';
@@ -19,6 +19,7 @@ function isRecord(value) {
19
19
  function asNonEmptyString(value) {
20
20
  return typeof value === "string" && value.trim() !== "" ? value : undefined;
21
21
  }
22
+ const MIN_FEED_IMAGE_SIDE = 100;
22
23
  function mediaAttribute(value, key) {
23
24
  if (!isRecord(value))
24
25
  return undefined;
@@ -26,9 +27,37 @@ function mediaAttribute(value, key) {
26
27
  return value.$[key];
27
28
  return value[key];
28
29
  }
30
+ function asMediaEntries(value) {
31
+ return Array.isArray(value) ? value : [value];
32
+ }
33
+ function parseDimension(value) {
34
+ if (typeof value === "number")
35
+ return Number.isFinite(value) && value > 0 ? value : null;
36
+ if (typeof value !== "string")
37
+ return null;
38
+ const match = /^\s*(\d+(?:\.\d+)?)\s*(?:px)?\s*$/i.exec(value);
39
+ if (!match)
40
+ return null;
41
+ const parsed = Number(match[1]);
42
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
43
+ }
44
+ function isTooSmallMedia(widthRaw, heightRaw) {
45
+ const width = parseDimension(widthRaw);
46
+ const height = parseDimension(heightRaw);
47
+ return (width !== null && width < MIN_FEED_IMAGE_SIDE) || (height !== null && height < MIN_FEED_IMAGE_SIDE);
48
+ }
29
49
  function cleanImageUrl(url) {
30
50
  return url.trim().replace(/&(?:#038|amp);/g, "&");
31
51
  }
52
+ export function isAvatarImageUrl(url) {
53
+ try {
54
+ const host = new URL(url.trim()).hostname.toLowerCase();
55
+ return host === "avatars.githubusercontent.com" || host.endsWith(".avatars.githubusercontent.com");
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
32
61
  function isValidImageUrl(url) {
33
62
  if (typeof url !== "string")
34
63
  return false;
@@ -44,39 +73,66 @@ function isValidImageUrl(url) {
44
73
  const host = parsed.hostname.toLowerCase();
45
74
  if (host === "pixel.wp.com" || host.endsWith(".pixel.wp.com"))
46
75
  return false;
76
+ if (isAvatarImageUrl(url))
77
+ return false;
47
78
  const pathAndQuery = (parsed.pathname + parsed.search).toLowerCase();
48
79
  if (pathAndQuery.includes("/1x1") || pathAndQuery.includes("pixel") || pathAndQuery.includes("tracking") || pathAndQuery.includes("beacon")) {
49
80
  return false;
50
81
  }
51
82
  return true;
52
83
  }
84
+ function htmlAttribute(tag, name) {
85
+ const match = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(tag);
86
+ return match ? (match[1] ?? match[2] ?? match[3]) : undefined;
87
+ }
53
88
  function firstHtmlImageUrl(html) {
54
89
  if (typeof html !== "string" || !html.includes("<img"))
55
90
  return null;
56
- const match = html.match(/<img[^>]+src=["'](https?:\/\/[^"'\s>]+)["']/i);
57
- return match && isValidImageUrl(match[1]) ? cleanImageUrl(match[1]) : null;
91
+ for (const [tag] of html.matchAll(/<img\b[^>]*>/gi)) {
92
+ const src = htmlAttribute(tag, "src");
93
+ if (!src)
94
+ continue;
95
+ const decodedSrc = decodeEntities(src);
96
+ if (!isValidImageUrl(decodedSrc))
97
+ continue;
98
+ if (isTooSmallMedia(htmlAttribute(tag, "width"), htmlAttribute(tag, "height")))
99
+ continue;
100
+ const classes = htmlAttribute(tag, "class") ?? "";
101
+ if (/\b(?:avatar|emoji|icon)\b/i.test(classes))
102
+ continue;
103
+ return cleanImageUrl(decodedSrc);
104
+ }
105
+ return null;
58
106
  }
59
107
  function extractXmlImageUrl(item) {
60
108
  // 1. media:content (Media RSS)
61
109
  const mediaContent = item.mediaContent ?? item["media:content"];
62
110
  if (mediaContent) {
63
- if (isValidImageUrl(mediaContent))
64
- return cleanImageUrl(mediaContent);
65
- const url = mediaAttribute(mediaContent, "url");
66
- const medium = mediaAttribute(mediaContent, "medium");
67
- const type = mediaAttribute(mediaContent, "type");
68
- if (isValidImageUrl(url) && (medium === "image" || !medium || (typeof type === "string" && type.startsWith("image/")))) {
69
- return cleanImageUrl(url);
111
+ for (const entry of asMediaEntries(mediaContent)) {
112
+ if (isValidImageUrl(entry))
113
+ return cleanImageUrl(entry);
114
+ if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
115
+ continue;
116
+ const url = mediaAttribute(entry, "url");
117
+ const medium = mediaAttribute(entry, "medium");
118
+ const type = mediaAttribute(entry, "type");
119
+ if (isValidImageUrl(url) && (medium === "image" || !medium || (typeof type === "string" && type.startsWith("image/")))) {
120
+ return cleanImageUrl(url);
121
+ }
70
122
  }
71
123
  }
72
124
  // 2. media:thumbnail
73
125
  const mediaThumbnail = item.mediaThumbnail ?? item["media:thumbnail"];
74
126
  if (mediaThumbnail) {
75
- if (isValidImageUrl(mediaThumbnail))
76
- return cleanImageUrl(mediaThumbnail);
77
- const url = mediaAttribute(mediaThumbnail, "url");
78
- if (isValidImageUrl(url))
79
- return cleanImageUrl(url);
127
+ for (const entry of asMediaEntries(mediaThumbnail)) {
128
+ if (isValidImageUrl(entry))
129
+ return cleanImageUrl(entry);
130
+ if (isTooSmallMedia(mediaAttribute(entry, "width"), mediaAttribute(entry, "height")))
131
+ continue;
132
+ const url = mediaAttribute(entry, "url");
133
+ if (isValidImageUrl(url))
134
+ return cleanImageUrl(url);
135
+ }
80
136
  }
81
137
  // 3. enclosure
82
138
  if (item.enclosure?.url) {
@@ -2,6 +2,7 @@ import { config } from "../config.js";
2
2
  import { db } from "../db/index.js";
3
3
  import { articleText } from "./articleContent.js";
4
4
  import { LEAD_VERSION } from "./contentNoise.js";
5
+ import { isAvatarImageUrl } from "./feedParser.js";
5
6
  import { largerHeroImage } from "./heroImage.js";
6
7
  import { refreshGalleryClassification, refreshLead } from "./lead.js";
7
8
  import { decodeEntities, plainTitle } from "./text.js";
@@ -206,7 +207,8 @@ export function upsertItems(feedId, items) {
206
207
  // a feed that alternates between two variants would change the content on every poll.
207
208
  const keptPrevious = retained !== null && next !== retained;
208
209
  const nextSnippet = keptPrevious ? null : row.contentSnippet ?? null;
209
- const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? previous?.image_url ?? row.imageUrl ?? null;
210
+ const reusablePreviousImage = previous?.image_url && !isAvatarImageUrl(previous.image_url) ? previous.image_url : null;
211
+ const nextImage = largerHeroImage(row.imageUrl, retained, row.link ?? previous?.link ?? null) ?? reusablePreviousImage ?? row.imageUrl ?? null;
210
212
  if (previous) {
211
213
  const changed = (row.title !== undefined && row.title !== previous.title) ||
212
214
  (row.link !== undefined && row.link !== previous.link) ||
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.42.4",
3
+ "version": "0.42.5",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }