forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
26 lines (25 loc) · 1.31 KB
/
filter.js
File metadata and controls
26 lines (25 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module.exports = async (ctx, next) => {
await next();
if (ctx.state.data && ctx.query && (ctx.query.filter || ctx.query.filter_title || ctx.query.filter_description)) {
ctx.state.data.item = ctx.state.data.item.filter((item) => {
const title = item.title;
const description = item.description;
return !(
(ctx.query.filter && !title.match(ctx.query.filter) && !description.match(ctx.query.filter)) ||
(ctx.query.filter_title && !title.match(ctx.query.filter_title)) ||
(ctx.query.filter_description && !description.match(ctx.query.filter_description))
);
});
}
if (ctx.state.data && ctx.query && (ctx.query.filterout || ctx.query.filterout_title || ctx.query.filterout_description)) {
ctx.state.data.item = ctx.state.data.item.filter((item) => {
const title = item.title;
const description = item.description;
return (
(ctx.query.filterout && !title.match(ctx.query.filterout) && !description.match(ctx.query.filterout)) ||
(ctx.query.filterout_title && !title.match(ctx.query.filterout_title)) ||
(ctx.query.filterout_description && !description.match(ctx.query.filterout_description))
);
});
}
};