From 1b9f1a9c41fa5134c4f6a8b1cd49da6ba8f4f963 Mon Sep 17 00:00:00 2001 From: Robert DeLuca Date: Mon, 12 Aug 2024 20:46:01 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Exclude=20item=20if=20there's=20?= =?UTF-8?q?no=20`pubDate`=20&=20if=20its=20in=20the=20future?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index f99acc3..8b95644 100755 --- a/index.js +++ b/index.js @@ -57,17 +57,21 @@ export const fetchFeed = async (url, lastPublishedDates) => { if (isDebug) core.debug(`Parsed items for ${url}: ${JSON.stringify(items)}`); - return items.map(item => ({ - title: item.title, - link: item.link, - publishedDate: new Date(item.pubDate).toISOString(), - })).filter(article => { - let lastPublished = lastPublishedDates[url]; - let isNew = !lastPublished || new Date(article.publishedDate) > new Date(lastPublished); - - if (isDebug) core.debug(`Article "${article.title}" is new: ${isNew}`); - return isNew; - }); + return items + .filter(item => item.pubDate) + .map(item => ({ + title: item.title, + link: item.link, + publishedDate: new Date(item.pubDate).toISOString(), + })) + .filter(article => { + let lastPublished = lastPublishedDates[url]; + let publishedDate = new Date(article.publishedDate); + let isNew = !lastPublished || (publishedDate > new Date(lastPublished) && publishedDate <= new Date()); + + if (isDebug) core.debug(`Article "${article.title}" is new: ${isNew}`); + return isNew; + }); } catch (error) { core.error(`Error fetching feed: ${error.message}`); return [];