mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 05:59:00 +08:00
fix: if fulltext parser failed, return default description and… (#2992)
This commit is contained in:
@@ -19,16 +19,21 @@ module.exports = async (ctx, next) => {
|
|||||||
const tasks = ctx.state.data.item.map(async (item) => {
|
const tasks = ctx.state.data.item.map(async (item) => {
|
||||||
const { link, author, description } = item;
|
const { link, author, description } = item;
|
||||||
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
|
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
|
||||||
|
// if parser failed, return default description and not report error
|
||||||
|
try {
|
||||||
const res = await got(link);
|
const res = await got(link);
|
||||||
const $ = cheerio.load(res.data);
|
const $ = cheerio.load(res.data);
|
||||||
const result = await mercury_parser.parse(link, {
|
const result = await mercury_parser.parse(link, {
|
||||||
html: $.html(),
|
html: $.html(),
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
// no-empty
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
item.author = author || parsed_result.author;
|
item.author = author || (parsed_result ? parsed_result.author : '');
|
||||||
item.description = parsed_result.content || description;
|
item.description = parsed_result ? parsed_result.content : description;
|
||||||
});
|
});
|
||||||
await Promise.all(tasks);
|
await Promise.all(tasks);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user