diff --git a/lib/routes/zsnews/index.js b/lib/routes/zsnews/index.js index be0c2d49a..72213760c 100644 --- a/lib/routes/zsnews/index.js +++ b/lib/routes/zsnews/index.js @@ -1,18 +1,32 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { ctx.params.cateid = ctx.params.cateid || '35'; const response = await got.get(`http://www.zsnews.cn/api/mobile/getlist.html?cateid=${ctx.params.cateid}`); + const out = await Promise.all( + response.data.map( + async (item) => + await ctx.cache.tryGet(item.url, async () => { + try { + const res = await got.get(item.url); + const $ = cheerio.load(res.data); + item.description = $('.article-content').html(); + item.pubDate = new Date($('.article-meta span').first().text().slice(5)).toUTCString(); + item.link = item.url; + return item; + } catch (err) { + return Promise.resolve(''); + } + }) + ) + ); + ctx.state.data = { title: '中山新闻', link: 'https://www.zsnews.cn/', - item: response.data.map((item) => ({ - guid: item.id, - title: item.title, - description: item.title, - link: item.url, - })), + item: out, }; };