refactor: avoid promise overhead (#8028)

This commit is contained in:
Sukka
2021-08-17 02:45:53 +08:00
committed by GitHub
parent 8053b33b03
commit 6e3b58ed1d
543 changed files with 5295 additions and 5694 deletions

View File

@@ -26,29 +26,28 @@ module.exports = async (ctx) => {
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('.img-article-item')
.find('img')
.each(function () {
content(this).attr('src', content(this).prev().attr('data-srcset').split('?')[0]);
});
const content = cheerio.load(detailResponse.data);
content('.img-article-item')
.find('img')
.each(function () {
content(this).attr('src', content(this).prev().attr('data-srcset').split('?')[0]);
});
content('.ad-zone-container, .sharing, .sentinel-article-nextArticle, .article-tags, .w-article-author-bio, .ml-form-embedContainer').remove();
content('.ad-zone-container, .sharing, .sentinel-article-nextArticle, .article-tags, .w-article-author-bio, .ml-form-embedContainer').remove();
item.description = content('.article-body').html();
item.author = content('a.author').text().replace('By ', '');
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
item.description = content('.article-body').html();
item.author = content('a.author').text().replace('By ', '');
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
return item;
})
return item;
})
)
);