cybrkyd

Tweaks to my HTML RSS feed reader and aggregator

 Mon, 07 Jul 2025 09:05 UTC
Tweaks to my HTML RSS feed reader and aggregator
Image: CC BY 4.0 by cybrkyd

I have slightly tweaked my RSS feed reader and aggregator by adding a snippet to filter posts older than 10 days from the feed. Since most (some) bloggers don’t post daily, my feed will soon start displaying very old posts, and that’s not what I want to see.

The original snippet:

  for (const { url, label } of feeds) {
    try {
      const doc = await fetchFeed(url);
      const items = parseFeed(doc).map(item => ({ ...item, source: label }));
      allItems.push(...items);
    } catch (err) {
      console.error(`Error parsing ${url}:`, err);
    }

The change:

for (const { url, label } of feeds) {
  try {
    const doc = await fetchFeed(url);
    const now = new Date();
    const tenDaysAgo = new Date(now);
    tenDaysAgo.setDate(now.getDate() - 10);

    const items = parseFeed(doc)
      .filter(item => item.date >= tenDaysAgo)
      .slice(0, ITEMS_PER_FEED)
      .map(item => ({ ...item, source: label }));

    allItems.push(...items);
  } catch (err) {
    console.error(`Error parsing ${url}:`, err);
»
Tagged in:

Visitors: Loading...