mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +08:00
feat(middleware): brief parameter (#8074)
Co-authored-by: SettingDust <settingdust@gmail.com> Co-authored-by: ギャラ <me@gyara.moe>
This commit is contained in:
@@ -239,6 +239,29 @@ module.exports = async (ctx, next) => {
|
||||
item.description = simplecc(item.description, ctx.query.opencc);
|
||||
});
|
||||
}
|
||||
|
||||
// brief
|
||||
if (ctx.query.brief) {
|
||||
const num = /[1-9]\d{2,}/;
|
||||
if (num.test(ctx.query.brief)) {
|
||||
ctx.query.brief = parseInt(ctx.query.brief);
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
let text;
|
||||
if (item.description) {
|
||||
text = item.description.replace(/<\/?[^>]+(>|$)/g, '');
|
||||
}
|
||||
if (text && text.length) {
|
||||
if (text.length > ctx.query.brief) {
|
||||
item.description = `<p>${text.substring(0, ctx.query.brief)}…</p>`;
|
||||
} else {
|
||||
item.description = `<p>${text}</p>`;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
throw Error(`Invalid parameter <code>brief=${ctx.query.brief}</code>. Please check the doc https://docs.rsshub.app/parameter.html#shu-chu-jian-xun`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user