diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index f184687161..8c0b9e8387 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -390,12 +390,12 @@ Parameters can be obtained from the official website, for instance: ### Category/Topic/Author - + - `:category`: - | World | Business | Legal | Markets | Breakingviews | Technology | - | -------- | ------- | ----- | -------- | ------------- | ---------- | - | world | business | legal | markets | breakingviews | technology | + | World | Business | Legal | Markets | Breakingviews | Technology | Graphics | + | ----- | -------- | ----- | ------- | ------------- | ---------- | -------- | + | world | business | legal | markets | breakingviews | technology | graphics | - `world/:topic`: diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 6aa2b93b49..800d0e7e91 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1524,12 +1524,12 @@ category 对应的关键词有 ### 分类 / 话题 / 作者 - + - `:category`: - | World | Business | Legal | Markets | Breakingviews | Technology | - | ----- | -------- | ----- | ------- | ------------- | ---------- | - | world | business | legal | markets | breakingviews | technology | + | World | Business | Legal | Markets | Breakingviews | Technology | Graphics | + | ----- | -------- | ----- | ------- | ------------- | ---------- | -------- | + | world | business | legal | markets | breakingviews | technology | graphics | - `world/:topic`: diff --git a/lib/v2/reuters/common.js b/lib/v2/reuters/common.js index a888323b61..f72250926c 100644 --- a/lib/v2/reuters/common.js +++ b/lib/v2/reuters/common.js @@ -7,33 +7,35 @@ const path = require('path'); module.exports = async (ctx) => { const category = ctx.params.category; const topic = ctx.params.topic ?? (category === 'authors' ? 'reuters' : ''); + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 20; const rootUrl = 'https://www.reuters.com'; const currentUrl = topic ? `${rootUrl}/${category}/${topic}/` : `${rootUrl}/${category}/`; const response = await got(currentUrl); const $ = cheerio.load(response.data); - let list = $('.media-story-card__body__3tRWy a.media-story-card__heading__eqhp9') + let items = $('.media-story-card__body__3tRWy a.media-story-card__heading__eqhp9, a.svelte-pxbp38, a.svelte-11dknnx, a.svelte-e21rsn') + .slice(0, limit) .toArray() .map((item) => { item = $(item); item.find('span.visually-hidden__hidden__2qXMW').remove(); return { title: item.text(), - link: rootUrl + item.prop('href'), + link: new URL(item.prop('href'), rootUrl).href, }; }); - if (!list.length) { + if (!items.length) { const metadata = $('script#fusion-metadata').html(); const metadataObj = JSON.parse(metadata.match(/Fusion.globalContent=(\{[\s\S]*?});/)[1]); const articles = metadataObj.arcResult?.articles ?? metadataObj.result?.articles ?? []; - list = articles.map((article) => ({ + items = articles.map((article) => ({ title: article.title, link: rootUrl + article.canonical_url, })); } - const items = await Promise.all( - list.map((item) => + items = await Promise.all( + items.map((item) => ctx.cache.tryGet(item.link, async () => { const detailResponse = await got(item.link); const content = cheerio.load(detailResponse.data); @@ -51,19 +53,34 @@ module.exports = async (ctx) => { return item; } - const data = JSON.parse( - content('script#fusion-metadata') - .text() - .match(/Fusion.globalContent=(\{[\s\S]*?});/)[1] - ); + const matches = content('script#fusion-metadata') + .text() + .match(/Fusion.globalContent=(\{[\s\S]*?});/); - item.title = data.result.title || item.title; - item.description = art(path.join(__dirname, 'templates/description.art'), { - result: data.result, - }); - item.pubDate = parseDate(data.result.display_time); - item.author = data.result.authors.map((author) => author.name).join(', '); - item.category = data.result.taxonomy.keywords; + if (matches) { + const data = JSON.parse(matches[1]); + + item.title = data.result.title || item.title; + item.description = art(path.join(__dirname, 'templates/description.art'), { + result: data.result, + }); + item.pubDate = parseDate(data.result.display_time); + item.author = data.result.authors.map((author) => author.name).join(', '); + item.category = data.result.taxonomy.keywords; + + return item; + } + + content('.title').remove(); + content('.article-metadata').remove(); + + item.title = content('meta[property="og:title"]').attr('content'); + item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*?)","dateModified/)[1]); + item.author = detailResponse.data + .match(/{"@type":"Person","name":"(.*?)"}/g) + .map((p) => p.match(/"name":"(.*?)"/)[1]) + .join(', '); + item.description = content('article').html(); return item; }) diff --git a/lib/v2/reuters/maintainer.js b/lib/v2/reuters/maintainer.js index f3b905d8b2..3e66dfaba5 100644 --- a/lib/v2/reuters/maintainer.js +++ b/lib/v2/reuters/maintainer.js @@ -2,5 +2,5 @@ module.exports = { '/investigates': ['LyleLee'], '/reuters/channel/:site/:channel': ['LyleLee'], // deprecated '/reuters/theWire': ['LyleLee'], // deprecated - '/:category/:topic?': ['LyleLee', 'HenryQW', 'proletarius101', 'black-desk'], + '/:category/:topic?': ['LyleLee', 'HenryQW', 'proletarius101', 'black-desk', 'nczitzk'], };