mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
perf: lazy require dependencies (#8025)
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
const entities = require('entities');
|
||||
const mercury_parser = require('@postlight/mercury-parser');
|
||||
const cheerio = require('cheerio');
|
||||
const { simplecc } = require('simplecc-wasm');
|
||||
const got = require('@/utils/got');
|
||||
const config = require('@/config').value;
|
||||
|
||||
let mercury_parser;
|
||||
|
||||
module.exports = async (ctx, next) => {
|
||||
await next();
|
||||
|
||||
@@ -204,6 +205,8 @@ module.exports = async (ctx, next) => {
|
||||
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
|
||||
// if parser failed, return default description and not report error
|
||||
try {
|
||||
mercury_parser = mercury_parser || require('@postlight/mercury-parser');
|
||||
|
||||
const res = await got(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
const result = await mercury_parser.parse(link, {
|
||||
|
||||
Reference in New Issue
Block a user