40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const rootUrl = 'https://www.reuters.com';
|
|
const currentUrl = `${rootUrl}/investigates/`;
|
|
const response = await got(currentUrl);
|
|
|
|
const $ = cheerio.load(response.data);
|
|
|
|
const list = $('article.section-article-container.row')
|
|
.map((_, item) => ({
|
|
title: $(item).find('h2.subtitle').text(),
|
|
link: $(item).find('a.row.d-flex').prop('href'),
|
|
}))
|
|
.get();
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got(item.link);
|
|
const content = cheerio.load(detailResponse.data);
|
|
|
|
item.title = content('title').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');
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('h1.series-subtitle').text(),
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
};
|