diff --git a/lib/routes/szse/rule.js b/lib/routes/szse/rule.js index 1bfd3e16f..6b12650eb 100644 --- a/lib/routes/szse/rule.js +++ b/lib/routes/szse/rule.js @@ -1,4 +1,3 @@ -const url = require('url'); const got = require('@/utils/got'); const cheerio = require('cheerio'); @@ -16,15 +15,32 @@ module.exports = async (ctx) => { const s = item.find('script').html(); return { title: s.match(/var curTitle ='(.*?)';/)[1], - link: url.resolve(`http://www.szse.cn/lawrules/rule`, s.match(/var curHref = '..(.*?)';/)[1]), + link: `http://www.szse.cn/lawrules/rule${s.match(/var curHref = '..(.*?)';/)[1]}`, pubDate: new Date(item.find('span.time').text().trim()).toUTCString(), }; }) .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, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('#desContent').html(); + + return item; + }) + ) + ); + ctx.state.data = { title: '深圳证券交易所 - 最新规则', link: currentUrl, - item: list, + item: items, }; };