diff --git a/lib/routes/tencent/news/author.js b/lib/routes/tencent/news/author.js index a5e9b8158c..03b870a3ff 100644 --- a/lib/routes/tencent/news/author.js +++ b/lib/routes/tencent/news/author.js @@ -1,4 +1,7 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); +const iconv = require('iconv-lite'); module.exports = async (ctx) => { const mid = ctx.params.mid; @@ -12,24 +15,39 @@ module.exports = async (ctx) => { const reponse = response.data; const title = reponse.mediainfo.name; const description = reponse.mediainfo.intro; - const list = reponse.data; + const list = reponse.data.splice(0, 10); - const items = list.map((item) => { - const title = item.title; - const date = Date(item.timestamp); - const itemUrl = item.vurl; - const author = item.source; - const description = item.abstract; + const items = await Promise.all( + list.map(async (item) => { + const title = item.title; + const unixTimestamp = new Date(item.timestamp * 1000); + const pubDate = date(unixTimestamp.toLocaleString(), 8); + const itemUrl = item.vurl; + const author = item.source; + const abstract = item.abstract; + + const response = await ctx.cache.tryGet( + itemUrl, + async () => + (await got.get(itemUrl, { + responseType: 'buffer', + })).data + ); + const html = iconv.decode(response, 'gbk'); + const $ = cheerio.load(html, { decodeEntities: false }); + const article = $('div.content-article'); + + const single = { + title, + description: article.html() || abstract, + link: itemUrl, + author, + pubDate, + }; + return Promise.resolve(single); + }) + ); - const single = { - title, - description, - link: itemUrl, - author, - pubDate: date, - }; - return single; - }); ctx.state.data = { title: title, description: description,