mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +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
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
const got = require('@/utils/got'); // get web content
|
||||
const cheerio = require('cheerio'); // html parser
|
||||
const he = require('he');
|
||||
const entities = require('entities');
|
||||
|
||||
const base_url = 'https://www.aozora.gr.jp/index_pages/';
|
||||
module.exports = async (ctx) => {
|
||||
@@ -50,7 +50,7 @@ module.exports = async (ctx) => {
|
||||
let title = '';
|
||||
let title_sub = '';
|
||||
for (let j = 0; j < title_info.length; ++j) {
|
||||
const tmp = he.decode($(title_info[j]).html()); // should convert from escaped to unicode
|
||||
const tmp = entities.decodeXML($(title_info[j]).html()); // should convert from escaped to unicode
|
||||
if (tmp.includes('作品名:')) {
|
||||
title = $(title_info[j]).find('td:nth-child(2)').text();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const got = require('@/utils/got');
|
||||
const cache = require('./cache');
|
||||
const he = require('he');
|
||||
const entities = require('entities');
|
||||
const queryString = require('query-string');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
@@ -25,7 +25,7 @@ module.exports = async (ctx) => {
|
||||
link: host,
|
||||
item: data.map((item) => ({
|
||||
title: item.subject,
|
||||
description: he.escape(he.escape(item.content)).replace(/\n/g, '<br>'),
|
||||
description: entities.escape(entities.escape(item.content)).replace(/\n/g, '<br>'),
|
||||
pubDate: new Date(item.date).toUTCString(),
|
||||
link: item.web_url,
|
||||
})),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const he = require('he');
|
||||
const entities = require('entities');
|
||||
const cheerio = require('cheerio');
|
||||
const date = require('@/utils/date');
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = async (ctx) => {
|
||||
const matchs = /"(url|temp_url)":"([^"]+mp\.weixin\.qq\.com[^"]+)"/.exec(response);
|
||||
let weixinLink = '';
|
||||
if (matchs && matchs[2]) {
|
||||
weixinLink = he.unescape(unescape(matchs[2].replace(/\\u/g, '%u')));
|
||||
weixinLink = entities.decodeXML(unescape(matchs[2].replace(/\\u/g, '%u')));
|
||||
}
|
||||
|
||||
const single = {
|
||||
|
||||
+3
-3
@@ -2,13 +2,14 @@
|
||||
"name": "rsshub",
|
||||
"version": "1.0.0",
|
||||
"description": "Make RSS Great Again!",
|
||||
"main": "lib/pkg.js",
|
||||
"main": "lib/workers_index.js",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"start": "node lib/index.js",
|
||||
"dev": "cross-env NODE_ENV=dev nodemon --inspect lib/index.js",
|
||||
"profiling": "NODE_ENV=production node --prof lib/index.js",
|
||||
"docs:dev": "vuepress dev docs",
|
||||
"docs:build": "vuepress build docs",
|
||||
"format": "eslint \"**/*.js\" --fix && node docs/.format/format.js && prettier \"**/*.{js,json}\" --write",
|
||||
@@ -41,7 +42,6 @@
|
||||
"@vuepress/plugin-google-analytics": "1.7.1",
|
||||
"@vuepress/plugin-pwa": "1.7.1",
|
||||
"cross-env": "7.0.3",
|
||||
"entities": "2.1.0",
|
||||
"eslint": "7.16.0",
|
||||
"eslint-config-prettier": "7.1.0",
|
||||
"eslint-plugin-prettier": "3.3.0",
|
||||
@@ -78,12 +78,12 @@
|
||||
"dayjs": "1.9.7",
|
||||
"dotenv": "8.2.0",
|
||||
"emailjs-imap-client": "3.1.0",
|
||||
"entities": "2.1.0",
|
||||
"etag": "1.8.1",
|
||||
"fanfou-sdk": "4.2.0",
|
||||
"git-rev-sync": "3.0.1",
|
||||
"googleapis": "66.0.0",
|
||||
"got": "11.8.1",
|
||||
"he": "1.2.0",
|
||||
"https-proxy-agent": "5.0.0",
|
||||
"iconv-lite": "0.6.2",
|
||||
"instagram-private-api": "1.43.3",
|
||||
|
||||
Reference in New Issue
Block a user