mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
chore: optimize performance (replace he with entities) (#6497)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const he = require('he');
|
||||
const entities = require('entities');
|
||||
const mercury_parser = require('@postlight/mercury-parser');
|
||||
const cheerio = require('cheerio');
|
||||
const OpenCC = require('opencc');
|
||||
@@ -24,14 +24,14 @@ module.exports = async (ctx, next) => {
|
||||
ctx.state.data.item = ctx.state.data.item || [];
|
||||
|
||||
// decode HTML entities
|
||||
ctx.state.data.title && (ctx.state.data.title = he.decode(ctx.state.data.title + ''));
|
||||
ctx.state.data.description && (ctx.state.data.description = he.decode(ctx.state.data.description + ''));
|
||||
ctx.state.data.title && (ctx.state.data.title = entities.decodeXML(ctx.state.data.title + ''));
|
||||
ctx.state.data.description && (ctx.state.data.description = entities.decodeXML(ctx.state.data.description + ''));
|
||||
|
||||
// sort items
|
||||
ctx.state.data.item = ctx.state.data.item.sort((a, b) => +new Date(b.pubDate || 0) - +new Date(a.pubDate || 0));
|
||||
|
||||
ctx.state.data.item.forEach((item) => {
|
||||
item.title && (item.title = he.decode(item.title + ''));
|
||||
const handleItem = async (item) => {
|
||||
item.title && (item.title = entities.decodeXML(item.title + ''));
|
||||
|
||||
// handle pubDate
|
||||
if (item.pubDate) {
|
||||
@@ -111,9 +111,12 @@ module.exports = async (ctx, next) => {
|
||||
$ele.removeAttr(e);
|
||||
});
|
||||
});
|
||||
item.description = he.decode($('body').html() + '') + (config.suffix || '');
|
||||
item.description = entities.decodeXML($('body').html() + '') + (config.suffix || '');
|
||||
}
|
||||
});
|
||||
return item;
|
||||
};
|
||||
|
||||
ctx.state.data.item = await Promise.all(ctx.state.data.item.map(handleItem));
|
||||
|
||||
if (ctx.query) {
|
||||
// limit
|
||||
|
||||
Reference in New Issue
Block a user