-
I've got a feed for archlinux pkgs, and I have a lot of Articles that are just sitting there, and I want to remove them while also rejecting blacklisted keywords from getting fetched. var whitelist = [
'firefox'
];
var blacklist = [
'firefox-developer-edition'
];
function filterMessage() {
if (whitelist.some(i => msg.title.indexOf(i) != -1)) {
if (blacklist.some(i => msg.title.indexOf(i) != -1)) {
return MessageObject.Ignore;
}
else {
return MessageObject.Accept;
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
It's helpful to think of it in terms of:
So you want to allow 'firefox' but not 'firefox-developer-edition' and ignore everything else. However, you've got Accept and Ignore the wrong way round:
This is because you want to run actions on the conditions and then ignore everything else. So we swap those:
Now onto the IF statement:
Remember, you're looking for:
Firstly, what I would highly recommend is to convert everything into lower case so you don't have to account for upper and lower case characters:
You have two if statements there when you only need one:
You need 'this' AND NOT 'that', so you use a double ampersand, '&&', to join them together. Then the extra curly brace '{' is not needed. To make something a NOT condition, notice how at the beginning of this line:
I've added '(!' meaning the exclamation mark is saying NOT. You need to excapsulate the NOT part inside a parenthesis, meaning you need to need another at the end to enclose it. You also had an extra curly brace right at the end which is not needed. So the final working filter would look like:
It sounds like you also have articles in your database already. If so and you would like to delete all of those, you can change:
to:
However, I would highly suggest that you do plenty of testing using the 'Test' button, rather than the 'Process checked feeds' button first and make sure it'll definitely only delete what you expect it to. Changing your filter to use Purge will not delete articles already in the database - you'd have to check the feed and click 'Process checked feeds' to do that. If you leave that line as Purge, then any new articles that would be filtered out will simply be ignored and won't be added to the database. |
Beta Was this translation helpful? Give feedback.
-
This is a variable (or set of variables):
This determines whether or not the articles match anything in the variables:
It's saying 'IF the articles contain SOME (meaning at least one of) the variables in the WHITELIST, then this condition is TRUE or else it's FALSE'. The '(!' part is to negate the above. You want to keep articles containing:
So you have a function in your filter (note the curly braces which opens to encapsulate the function and which is closed later on):
These conditions will evaluate to either TRUE or FALSE. The above translates as:
The actions being to either Accept the articles or Ignore or Purge them.
If both conditions are TRUE, then the article will be Accepted, else they will be Purged/Ignored. In the simplest terms:
The conditions are separate from the actions so there is no similarity there. |
Beta Was this translation helpful? Give feedback.
It's helpful to think of it in terms of:
So you want to allow 'firefox' but not 'firefox-developer-edition' and ignore everything else.
However, you've got Accept and Ignore the wrong way round:
This is because you want to run actions on the conditions and then ignore everything else.
So we swap those:
Now onto the IF statement:
Remember, you're looking for: