From 5bdbd2d762f093f02356ae20bf865c31ebbf70cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=95=BF=E5=AE=89?= Date: Wed, 30 Jan 2019 11:16:28 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=8D=B3=E5=88=BB=EF=BC=9A?= =?UTF-8?q?=E5=AF=B9=E4=B8=A4=E4=B8=AA=E6=96=B0=E9=97=BB=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=81=9A=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86=20(#1489)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改即刻 Feed,对两个新闻主题 [一觉醒来世界发生了什么](https://web.okjike.com/topic/553870e8e4b0cafb0a1bef68/official) 和 [今天网上都在热议什么](https://web.okjike.com/topic/55963702e4b0d84d2c30ce6f/official) 进行特殊处理: - 标题改为 `${主题名称} ${日期}` 如 `一觉醒来世界发生了什么 01月30日` - 为每个新闻添加源文链接 Reader 中效果如下: ![image](https://user-images.githubusercontent.com/21376471/51955323-76419700-247e-11e9-901c-58a3fe2e4ec4.png) ![image](https://user-images.githubusercontent.com/21376471/51955331-7a6db480-247e-11e9-9083-8148f1f41d3d.png) --- lib/routes/jike/topic.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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); + } };