Files
RSSHub/middleware/filter.js
T
tgly307 ead78bbd89 添加exclude过滤功能 (#186)
* 知乎日报全文rss

* reverse router.js

* 知乎日报当天全文rss

* Update daily.js

去除JSON处理方法,添加对redis的异步get兼容,统一缓存保留时间。

* git ignore

* 即刻topic广场信息

* Delete .gitignore

* Revert "Merge branch 'master' into master"

This reverts commit d2acb89f0b, reversing
changes made to 2c401dba0a.

* fix bug

* delete request for topic info

* 把缩略图改成原图

* 添加exclude过滤

* fix md
2018-05-23 14:23:03 +08:00

27 lines
1.3 KiB
JavaScript

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))
);
});
}
};