Skip to content

Commit

Permalink
πŸ› Exclude item if there's no pubDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Robdel12 committed Aug 13, 2024
1 parent ba1e3c9 commit ec19f85
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ 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 || item.lastBuildDate).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 isNew = !lastPublished || new Date(article.publishedDate) > new Date(lastPublished);

if (isDebug) core.debug(`Article "${article.title}" is new: ${isNew}`);
return isNew;
});
} catch (error) {
core.error(`Error fetching feed: ${error.message}`);
return [];
Expand Down

0 comments on commit ec19f85

Please sign in to comment.