diff --git a/lib/v2/reuters/common.js b/lib/v2/reuters/common.js index d585e1962e..10aaf7c17e 100644 --- a/lib/v2/reuters/common.js +++ b/lib/v2/reuters/common.js @@ -1,6 +1,8 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); module.exports = async (ctx) => { const category = ctx.params.category; @@ -12,15 +14,15 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); let list = $('.media-story-card__body__3tRWy a.media-story-card__heading__eqhp9') - .map((_, item) => { + .toArray() + .map((item) => { item = $(item); item.find('span.visually-hidden__hidden__2qXMW').remove(); return { title: item.text(), link: rootUrl + item.prop('href'), }; - }) - .get(); + }); if (!list.length) { const metadata = $('script#fusion-metadata').html(); const metadataObj = JSON.parse(metadata.match(/Fusion.globalContent=(\{[\s\S]*?});/)[1]); @@ -36,10 +38,19 @@ module.exports = async (ctx) => { const detailResponse = await got(item.link); const content = cheerio.load(detailResponse.data); - item.title = content('meta[property="og:title"]').attr('content') || item.title; - item.description = content('p[data-testid="paragraph-0"]').text(); - item.pubDate = parseDate(content('meta[name="article:published_time"]').attr('content')); - item.author = content('meta[name="article:author"]').attr('content'); + const data = JSON.parse( + content('script#fusion-metadata') + .text() + .match(/Fusion.globalContent=(\{[\s\S]*?});/)[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; }) @@ -47,7 +58,9 @@ module.exports = async (ctx) => { ); ctx.state.data = { - title: topic ? `Reuters - ${category} - ${topic}` : `Reuters - ${category}`, + title: $('head title').text(), + description: $('head meta[name=description]').attr('content'), + image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116', link: currentUrl, item: items, }; diff --git a/lib/v2/reuters/investigates.js b/lib/v2/reuters/investigates.js index 7be1a2799c..af9123fe07 100644 --- a/lib/v2/reuters/investigates.js +++ b/lib/v2/reuters/investigates.js @@ -22,7 +22,7 @@ module.exports = async (ctx) => { const content = cheerio.load(detailResponse.data); item.title = content('title').text(); - item.description = content('#paragraph-0').text(); + item.description = content('article.special-report').html(); item.pubDate = parseDate(content('time[itemprop="datePublished"]').attr('datetime')); item.author = content('meta[property="og:article:publisher"]').attr('content'); diff --git a/lib/v2/reuters/templates/description.art b/lib/v2/reuters/templates/description.art new file mode 100644 index 0000000000..adbc3ad174 --- /dev/null +++ b/lib/v2/reuters/templates/description.art @@ -0,0 +1,44 @@ +{{ if result.summary }} +Summary: +
{{@ e.content }}
{{ /if }} + {{ if e.type === 'header' }}