From 205cd603f04ffb23e007a9a1e6941934e9c730cc Mon Sep 17 00:00:00 2001 From: Aarti Date: Fri, 26 Apr 2024 14:52:32 -0400 Subject: [PATCH 1/2] Test Commit --- modules/default/newsfeed/newsfeed.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index c66f8990d8..8a2cbca1c2 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -24,8 +24,10 @@ Module.register("newsfeed", { updateInterval: 10 * 1000, animationSpeed: 2.5 * 1000, maxNewsItems: 0, // 0 for unlimited - ignoreOldItems: false, - ignoreOlderThan: 24 * 60 * 60 * 1000, // 1 day + // Lets make this an array, so it holds the value for each newsfeed, currently there is only one: New York Times + ignoreOldItems: Array.from({length: feeds.length}, () => false), + // Let's make this an array, so it holds the values for each newsfeed, currently there is only one: New York Times + ignoreOlderThan:Array.from({length: feeds.length}, () => 24 * 60 * 60 * 1000), // all feeds are set to 1 day removeStartTags: "", removeEndTags: "", startTags: [], @@ -183,12 +185,12 @@ Module.register("newsfeed", { */ generateFeed (feeds) { let newsItems = []; - for (let feed in feeds) { - const feedItems = feeds[feed]; - if (this.subscribedToFeed(feed)) { + for (let i = 0; i < feeds.length; i++) { + const feedItems = feeds[i]; + if (this.subscribedToFeed(feedItems)) { for (let item of feedItems) { - item.sourceTitle = this.titleForFeed(feed); - if (!(this.config.ignoreOldItems && Date.now() - new Date(item.pubdate) > this.config.ignoreOlderThan)) { + item.sourceTitle = this.titleForFeed(feedItems); + if (!(this.config.ignoreOldItems[i] && Date.now() - new Date(item.pubdate) > this.config.ignoreOlderThan[i])) { newsItems.push(item); } } From 1c502be53f91ba541c0ad5f3a9d85a115cdff66a Mon Sep 17 00:00:00 2001 From: Aarti Date: Fri, 26 Apr 2024 18:49:34 -0400 Subject: [PATCH 2/2] Added variables ignoreOldItems and ignoreOlderThan to each feed an made a function that returned values from the feed --- modules/default/newsfeed/newsfeed.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index 8a2cbca1c2..7373edb0ec 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -5,7 +5,9 @@ Module.register("newsfeed", { { title: "New York Times", url: "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml", - encoding: "UTF-8" //ISO-8859-1 + encoding: "UTF-8", //ISO-8859-1 + ignoreOldItems: false, + ignoreOlderThan: 24 * 60 * 60 * 1000 } ], showAsList: false, @@ -24,10 +26,10 @@ Module.register("newsfeed", { updateInterval: 10 * 1000, animationSpeed: 2.5 * 1000, maxNewsItems: 0, // 0 for unlimited - // Lets make this an array, so it holds the value for each newsfeed, currently there is only one: New York Times - ignoreOldItems: Array.from({length: feeds.length}, () => false), - // Let's make this an array, so it holds the values for each newsfeed, currently there is only one: New York Times - ignoreOlderThan:Array.from({length: feeds.length}, () => 24 * 60 * 60 * 1000), // all feeds are set to 1 day + // // Lets make this an array, so it holds the value for each newsfeed, currently there is only one: New York Times + // ignoreOldItems: Array.from({length: feeds.length}, () => false), + // // Let's make this an array, so it holds the values for each newsfeed, currently there is only one: New York Times + // ignoreOlderThan:Array.from({length: feeds.length}, () => 24 * 60 * 60 * 1000), // all feeds are set to 1 day removeStartTags: "", removeEndTags: "", startTags: [], @@ -178,7 +180,9 @@ Module.register("newsfeed", { }); } }, - + getFeedProperty(feed, property) { + return feed[property] || defaultValues[property]; + }, /** * Generate an ordered list of items for this configured module. * @param {object} feeds An object with feeds returned by the node helper. @@ -189,8 +193,10 @@ Module.register("newsfeed", { const feedItems = feeds[i]; if (this.subscribedToFeed(feedItems)) { for (let item of feedItems) { + let ignoreOldItems = getFeedProperty(feedItems, 'ignoreOldItems'); + let ignoreOlderThan = getFeedProperty(feedItems, 'ignoreOlderThan'); item.sourceTitle = this.titleForFeed(feedItems); - if (!(this.config.ignoreOldItems[i] && Date.now() - new Date(item.pubdate) > this.config.ignoreOlderThan[i])) { + if (!(ignoreOldItems && Date.now() - new Date(item.pubdate) > ignoreOlderThan)) { newsItems.push(item); } }