From fc7ce4aae7feb2d4cc7b7463bdb3172d17be54ae Mon Sep 17 00:00:00 2001 From: junbaor Date: Fri, 26 Jul 2019 13:21:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=203DM=20=E6=96=B0=E9=97=BB=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=20(#2694)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/3dm/news_center.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/routes/3dm/news_center.js b/lib/routes/3dm/news_center.js index 48857f1b5..07513dc75 100644 --- a/lib/routes/3dm/news_center.js +++ b/lib/routes/3dm/news_center.js @@ -9,25 +9,27 @@ module.exports = async (ctx) => { url: url, }); const $ = cheerio.load(res.data); - const list = $('.news_list .list li') - .slice(0, 10) - .get(); + const list = $('.Revision_list .selectpost').get(); const out = await Promise.all( list.map(async (i) => { const item = $(i); const itemUrl = $(item) - .find('.selectarcpost') + .find('.text') + .find('a') .attr('href'); const cache = await ctx.cache.get(itemUrl); if (cache) { return Promise.resolve(JSON.parse(cache)); } const title = $(item) - .find('.bt') - .text(); - const content = $(item) - .find('p') + .find('.text') + .find('a') .text(); + + const itemReponse = await got.get(itemUrl); + const itemElement = cheerio.load(itemReponse.data); + const description = itemElement('.news_warp_center').html(); + const pageInfo = $(item) .find('.time') .text(); @@ -35,9 +37,10 @@ module.exports = async (ctx) => { const regRes = regex.exec(pageInfo); const time = regRes === null ? new Date() : new Date(regRes[0]); time.setTime(time.getTime() + (sourceTimezoneOffset - time.getTimezoneOffset() / 60) * 60 * 60 * 1000); + const single = { title: title, - description: content, + description: description, pubDate: time.toUTCString(), link: itemUrl, guid: itemUrl, @@ -47,10 +50,13 @@ module.exports = async (ctx) => { return Promise.resolve(single); }) ); + ctx.state.data = { - title: $('title') - .text() - .split('_')[0], + title: + '3DM - ' + + $('title') + .text() + .split('_')[0], link: url, item: out, };