diff --git a/lib/routes/jike/topic.js b/lib/routes/jike/topic.js index cb6fa71a1..49f9b0760 100644 --- a/lib/routes/jike/topic.js +++ b/lib/routes/jike/topic.js @@ -1,5 +1,7 @@ const axios = require('../../utils/axios'); const common = require('./common'); +const cheerio = require('cheerio'); +const dayjs = require('dayjs'); module.exports = async (ctx) => { const id = ctx.params.id; @@ -32,4 +34,34 @@ module.exports = async (ctx) => { image: topic.squarePicture.picUrl || topic.squarePicture.middlePicUrl || topic.squarePicture.thumbnailUrl, item: common.topicDataHanding(data), }; + if (id === '553870e8e4b0cafb0a1bef68' || id === '55963702e4b0d84d2c30ce6f') { + const promises = ctx.state.data.item.map(async (one) => { + const item = { ...one }; + const regResult = /https:\/\/www.okjike.com\/medium\/[a-zA-Z0-9]*/.exec(item.description); + if (regResult) { + const newsUrl = regResult[0]; + const cache = ctx.cache.get(newsUrl); + if (cache) { + item.description = cache; + } else { + const { data } = await axios.get(newsUrl); + const $ = cheerio.load(data); + const upper = $('ul.main > li.item'); + const links = upper.find('a').map((_, ele) => $(ele).attr('href')); + const texts = upper.find('span.text').map((_, ele) => $(ele).text()); + let description = ''; + for (let i = 0; i < links.length; i++) { + description += `${i + 1}、${texts[i]}
`; + } + if (description) { + item.description = description; + ctx.cache.set(newsUrl, description); + } + } + } + item.title = `${topic.content} ${dayjs(new Date(one.pubDate)).format('MM月DD日')}`; + return item; + }); + ctx.state.data.item = await Promise.all(promises); + } };