fix: aliyun-kernel pub time error (#3750)

This commit is contained in:
localhost
2020-01-16 14:45:07 +08:00
committed by DIYgod
parent d516472f83
commit 5e7f826cf5
+8 -8
View File
@@ -14,21 +14,20 @@ module.exports = async (ctx) => {
const data = response.data;
const $ = cheerio.load(data);
const list = $('.container .post-item').get();
const ProcessFeed = (data) => {
const $ = cheerio.load(data);
// 提取内容
return $('.container .post-content').html();
return {
desc: $('.container .post-content').html(),
publish_time: $('.post-meta > time').attr('datetime'),
};
};
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const $a = $('.article-title > a');
const link = baseUrl + $a.attr('href');
// const publish_time = $('.date-label').text();
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
@@ -38,14 +37,15 @@ module.exports = async (ctx) => {
method: 'get',
url: link,
});
const description = ProcessFeed(response.data);
const feed = ProcessFeed(response.data);
const description = feed.desc;
const pubDate = feed.publish_time;
const single = {
title: $a.text(),
description,
link: link,
// pubDate: publish_time,
pubDate: pubDate,
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);