diff --git a/lib/v2/ruc/hr.js b/lib/v2/ruc/hr.js index c016a5f31..18befc901 100644 --- a/lib/v2/ruc/hr.js +++ b/lib/v2/ruc/hr.js @@ -15,29 +15,35 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); - const list = $('a[title]') - .map((_, item) => { + let items = $('a[title]') + .toArray() + .map((item) => { item = $(item); + const link = item.attr('href'); + return { title: item.text(), - link: `${rootUrl}/${category}/${item.attr('href')}`, + link: `${rootUrl}${link.indexOf('..') === 0 ? link.replace(/\.\./, '') : `/${category}/${link}`}`, }; - }) - .get(); + }); - const items = await Promise.all( - list.map((item) => + items = await Promise.all( + items.map((item) => ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + try { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - const content = cheerio.load(detailResponse.data); + const content = cheerio.load(detailResponse.data); - item.description = content('.neirong').html(); - item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]); + item.description = content('.neirong').html(); + item.pubDate = parseDate(detailResponse.data.match(/日期:(\d{4}-\d{2}-\d{2})/)[1]); + } catch (err) { + item.description = 'Not Found'; + } return item; })