fix: 3DM 新闻中心 (#2694)

This commit is contained in:
junbaor 2019-07-26 13:21:40 +08:00 committed by DIYgod
parent 865b6ab573
commit fc7ce4aae7
1 changed files with 18 additions and 12 deletions

View File

@ -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,
};