diff --git a/lib/routes/bjnews/news.js b/lib/routes/bjnews/news.js index 04c639cfb..9bd98734a 100644 --- a/lib/routes/bjnews/news.js +++ b/lib/routes/bjnews/news.js @@ -7,11 +7,8 @@ module.exports = async (ctx) => { const $ = cheerio.load(res.data); const list = $('#news_ul li').get(); - const proList = []; - const indexList = []; - const out = await Promise.all( - list.map(async (item, i) => { + list.map(async (item) => { const $ = cheerio.load(item); const time = $('p').text(); const title = $('a').text(); @@ -20,24 +17,21 @@ module.exports = async (ctx) => { if (cache) { return Promise.resolve(JSON.parse(cache)); } + + const responses = await axios.get(itemUrl); + const $d = cheerio.load(responses.data); + const single = { title, pubDate: new Date(time).toUTCString(), link: itemUrl, guid: itemUrl, + description: $d('#main .content').html(), }; - proList.push(axios.get(itemUrl)); - indexList.push(i); + ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60); return Promise.resolve(single); }) ); - const responses = await axios.all(proList); - for (let i = 0; i < responses.length; i++) { - const res = responses[i]; - const $ = cheerio.load(res.data); - out[indexList[i]].description = $('#main .content').html(); - ctx.cache.set(out[indexList[i]].link, JSON.stringify(out[i]), 24 * 60 * 60); - } ctx.state.data = { title: $('title').text(), link: url,