const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = `https://aeon.co/${ctx.params.cid}`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('.article-card').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const title = $('.article-card__title').text();
const partial = $('.article-card__title').attr('href');
const address = `https://aeon.co${partial}`;
const author = $('.article-card__authors__inner').text();
const cache = await ctx.cache.get(address);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const res = await got.get(address);
const capture = cheerio.load(res.data);
const time = capture('.article__date.published').text();
capture('div.newsletter-signup').remove();
capture('p.pullquote').remove();
capture('div.article__related').remove();
capture('div.article__shares').remove();
let bio;
const authorInfo = '.article__body__author-details > p:nth-child(2)';
if (capture(authorInfo).html() !== null) {
bio = `