diff --git a/server/routes.ts b/server/routes.ts index b363915..64c9cb1 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -364,7 +364,7 @@ export async function registerRoutes( } }); - function parseRssItems(xml: string): { title: string; link: string; source: string; pubDate: string }[] { + function parseRssItems(xml: string, maxAgeDays?: number): { title: string; link: string; source: string; pubDate: string }[] { const items: { title: string; link: string; source: string; pubDate: string }[] = []; const itemRegex = /([\s\S]*?)<\/item>/g; let match; @@ -377,6 +377,10 @@ export async function registerRoutes( let pubDate = ""; try { const d = new Date(pubDateRaw); + if (maxAgeDays !== undefined) { + const ageMs = Date.now() - d.getTime(); + if (ageMs > maxAgeDays * 24 * 3600000) continue; + } const diffH = Math.floor((Date.now() - d.getTime()) / 3600000); if (diffH < 1) pubDate = "Gerade eben"; else if (diffH < 24) pubDate = `vor ${diffH} Std.`; @@ -411,7 +415,7 @@ export async function registerRoutes( const topic = topics[Math.floor(Date.now() / 3600000) % topics.length]; const rssUrl = `https://news.google.com/rss/search?q=${topic}&hl=de&gl=DE&ceid=DE:de`; const xml = await fetchRssFeed(rssUrl); - const items = parseRssItems(xml); + const items = parseRssItems(xml, 14); if (items.length > 0) setCache(cacheKey, items); res.json(items); } catch (err: any) { @@ -431,7 +435,7 @@ export async function registerRoutes( const topic = topics[Math.floor(Date.now() / 3600000) % topics.length]; const rssUrl = `https://news.google.com/rss/search?q=${topic}&hl=de&gl=DE&ceid=DE:de`; const xml = await fetchRssFeed(rssUrl); - const items = parseRssItems(xml); + const items = parseRssItems(xml, 1); if (items.length > 0) setCache(cacheKey, items); res.json(items); } catch (err: any) {