Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Specific ignoreOlderThan value (override) per URL Feature #3429

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions modules/default/newsfeed/newsfeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
{
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,

Check failure on line 9 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Trailing spaces not allowed

Check failure on line 9 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Trailing spaces not allowed

Check failure on line 9 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Trailing spaces not allowed
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having ignorOldItems and ignorOlderThan be global parameters, I added them inside the feed array and gave then default values of false and 1day.

ignoreOlderThan: 24 * 60 * 60 * 1000
}
],
showAsList: false,
Expand All @@ -24,8 +26,10 @@
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

Check failure on line 31 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Trailing spaces not allowed

Check failure on line 31 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Trailing spaces not allowed

Check failure on line 31 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Trailing spaces not allowed
// ignoreOlderThan:Array.from({length: feeds.length}, () => 24 * 60 * 60 * 1000), // all feeds are set to 1 day

Check failure on line 32 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Trailing spaces not allowed

Check failure on line 32 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Trailing spaces not allowed

Check failure on line 32 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Trailing spaces not allowed
removeStartTags: "",
removeEndTags: "",
startTags: [],
Expand Down Expand Up @@ -176,19 +180,23 @@
});
}
},

getFeedProperty(feed, property) {

Check failure on line 183 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Missing space before function parentheses

Check failure on line 183 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Missing space before function parentheses

Check failure on line 183 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Missing space before function parentheses
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this function so you can access values inside the objects in the feed array.

return feed[property] || defaultValues[property];

Check failure on line 184 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'defaultValues' is not defined

Check failure on line 184 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

'defaultValues' is not defined

Check failure on line 184 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

'defaultValues' is not defined
},
/**

Check failure on line 186 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Expected line before comment

Check failure on line 186 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Expected line before comment

Check failure on line 186 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Expected line before comment
* Generate an ordered list of items for this configured module.
* @param {object} feeds An object with feeds returned by the node helper.
*/
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)) {
let ignoreOldItems = getFeedProperty(feedItems, 'ignoreOldItems');

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'getFeedProperty' is not defined

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Strings must use doublequote

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

'getFeedProperty' is not defined

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Strings must use doublequote

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

'getFeedProperty' is not defined

Check failure on line 196 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Strings must use doublequote
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed how the the variables are accessed when trying to display the feed by using the getFeedProperty()

let ignoreOlderThan = getFeedProperty(feedItems, 'ignoreOlderThan');

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

Mixed spaces and tabs

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (18.x)

'getFeedProperty' is not defined

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

Mixed spaces and tabs

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (20.x)

'getFeedProperty' is not defined

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

Mixed spaces and tabs

Check failure on line 197 in modules/default/newsfeed/newsfeed.js

View workflow job for this annotation

GitHub Actions / test (21.x)

'getFeedProperty' is not defined
item.sourceTitle = this.titleForFeed(feedItems);
if (!(ignoreOldItems && Date.now() - new Date(item.pubdate) > ignoreOlderThan)) {
newsItems.push(item);
}
}
Expand Down
Loading