fix: remove redundant promise

This commit is contained in:
DIYgod 2019-07-08 23:26:59 +08:00
parent dbdf676473
commit 905d8ffe44
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 11 additions and 18 deletions

View File

@ -24,25 +24,18 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
const list = $('#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const itemUrl = $('h3 a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title: $('h3 a').text(),
author: $('.gs_a').text(),
description: $('.gs_rs').text(),
link: itemUrl,
guid: itemUrl,
};
const out = list.map((item) => {
const $ = cheerio.load(item);
const itemUrl = $('h3 a').attr('href');
return {
title: $('h3 a').text(),
author: $('.gs_a').text(),
description: $('.gs_rs').text(),
link: itemUrl,
guid: itemUrl,
};
});
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `Google Scholar Monitor: ${query}`,
link: url,