feat: generate description for /guokr/scientific (#6342)

This commit is contained in:
Laam Pui 2020-12-06 10:03:59 -08:00 committed by GitHub
parent facbd716f4
commit 8db7c0042a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,5 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await got.get('https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_subject&limit=20&offset=0');
@ -9,12 +10,22 @@ module.exports = async (ctx) => {
title: '果壳网 科学人',
link: 'https://www.guokr.com/scientific',
description: '果壳网 科学人',
item: result.map((item) => ({
title: item.title,
description: `${item.summary}<br><img src="${item.image_info ? item.image_info.url : item.small_image}">`,
pubDate: item.date_published,
link: item.url,
author: item.author.nickname,
})),
item: await Promise.all(
result.map(
async (item) =>
await ctx.cache.tryGet(item.url, async () => {
const res = await got.get(item.url);
const $ = cheerio.load(res.data);
item.description = $('.eflYNZ #js_content').css('visibility', 'visible').html() || $('.bPfFQI').html();
return {
title: item.title,
description: item.description,
pubDate: item.date_published,
link: item.url,
author: item.author.nickname,
};
})
)
),
};
};