fix(route): economist article body extraction (#13368)

* fix(route): economist article body extraction

* fix: limit items

---------
This commit is contained in:
Joshua Peek 2023-09-22 11:54:30 -07:00 committed by GitHub
parent 06c725c086
commit f2ec5a8d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -9,7 +9,9 @@ const getArticleDetail = (link, ctx) =>
$('div.article-audio-player__center-tooltip').remove();
const nextData = JSON.parse($('head script[type="application/ld+json"]').first().text());
const article = ($('figure[class^=css-]').first().parent().parent().html() || '') + $('p.article__body-text').parent().html();
const figure = $('figure[class^=css-]').first().parent().parent().html() || '';
const body = $('p[data-component="paragraph"]').parent().parent().html();
const article = figure + body;
const categories = nextData.keywords?.map((k) => k);
return { article, categories };
@ -20,7 +22,7 @@ module.exports = async (ctx) => {
const feed = await parser.parseURL(`https://www.economist.com/${endpoint}/rss.xml`);
const items = await Promise.all(
feed.items.map(async (item) => {
feed.items.slice(0, ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30).map(async (item) => {
const path = item.link.slice(item.link.lastIndexOf('/') + 1);
const isNotCollection = !/^\d{4}-\d{2}-\d{2}$/.test(path);
const itemDetails = isNotCollection ? await getArticleDetail(item.link, ctx) : null;