rss: limit param
This commit is contained in:
+10
-4
@@ -35,12 +35,18 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
|
||||
|
||||
::: tip 提示
|
||||
|
||||
演示地址为 [rsshub.app](https://rsshub.app),缓存时间 10 分钟,可以随意使用,但请不要抓取过于频繁
|
||||
演示地址为 [rsshub.app](https://rsshub.app),缓存时间 10 分钟,可以随意使用
|
||||
|
||||
:::
|
||||
|
||||
## 通用参数
|
||||
|
||||
::: tip 提示
|
||||
|
||||
所有通用参数可以组合使用,效果叠加
|
||||
|
||||
:::
|
||||
|
||||
### 内容过滤
|
||||
|
||||
可以使用以下 URL query 过滤内容,支持正则
|
||||
@@ -65,11 +71,11 @@ filterout 去掉不要的内容
|
||||
|
||||
举例: [https://rsshub.app/bilibili/user/coin/2267573?filterout=微小微|赤九玖|暴走大事件](https://rsshub.app/bilibili/user/coin/2267573?filterout=微小微|赤九玖|暴走大事件)
|
||||
|
||||
::: tip 提示
|
||||
### 条数限制
|
||||
|
||||
filter 与 filterout 共 6 个 query 参数可以组合使用。当 filter、filter_title、filter_description 中多个参数存在时,取其交集进行过滤,filterout 三项同理。
|
||||
可以使用 limit 参数限制最大条数,主要用于排行榜类 RSS
|
||||
|
||||
:::
|
||||
举例:bilibili 排行榜前 10 [https://rsshub.app/bilibili/ranking/0/3?limit=10](https://rsshub.app/bilibili/ranking/0/3?limit=10)
|
||||
|
||||
### 输出格式
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ const header = require('./middleware/header.js');
|
||||
const utf8 = require('./middleware/utf8');
|
||||
const memoryCache = require('./middleware/lru-cache.js');
|
||||
const redisCache = require('./middleware/redis-cache.js');
|
||||
const filter = require('./middleware/filter.js');
|
||||
const parameter = require('./middleware/parameter.js');
|
||||
const template = require('./middleware/template.js');
|
||||
const favicon = require('koa-favicon');
|
||||
const debug = require('./middleware/debug.js');
|
||||
@@ -52,7 +52,7 @@ app.use(utf8);
|
||||
app.use(template);
|
||||
|
||||
// 3 filter content
|
||||
app.use(filter);
|
||||
app.use(parameter);
|
||||
|
||||
// 2 cache
|
||||
if (config.cacheType === 'memory') {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module.exports = async (ctx, next) => {
|
||||
await next();
|
||||
|
||||
// filter
|
||||
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;
|
||||
@@ -23,4 +24,9 @@ module.exports = async (ctx, next) => {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// limit
|
||||
if (ctx.state.data && ctx.query && ctx.query.limit) {
|
||||
ctx.state.data.item = ctx.state.data.item.slice(0, parseInt(ctx.query.limit));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user