From a48ec3cd82b3cc6fdf6a7218cf51572d1cd4ac5d Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Mon, 28 Feb 2022 20:44:10 +0800 Subject: [PATCH] fix(route): readhub add abstract (#9207) * fix(route): add abstract * fix(route): add an optional parameter to control show fulltext or overview --- docs/new-media.md | 2 +- lib/v2/readhub/index.js | 20 ++++++++++++++++---- lib/v2/readhub/maintainer.js | 2 +- lib/v2/readhub/radar.js | 4 ++-- lib/v2/readhub/router.js | 4 ++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/new-media.md b/docs/new-media.md index 791a94bb6..bd15fa93a 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1064,7 +1064,7 @@ IPFS 网关有可能失效,那时候换成其他网关。 ### 分类 - + | 热门话题 | 科技动态 | 技术资讯 | 区块链快讯 | 每日早报 | | ----- | ---- | ---- | ---------- | ----- | diff --git a/lib/v2/readhub/index.js b/lib/v2/readhub/index.js index 652e503a7..db8a86a83 100644 --- a/lib/v2/readhub/index.js +++ b/lib/v2/readhub/index.js @@ -5,13 +5,21 @@ const titles = { topic: '热门话题', news: '科技动态', tech: '技术资讯', + technews: '技术资讯', blockchain: '区块链快讯', daily: '每日早报', }; module.exports = async (ctx) => { - let category = ctx.params.category ?? 'topic'; - category = category === 'technews' ? 'tech' : category; + let category = 'topic'; + let overview = false; + if (titles[ctx.params.category]) { + category = ctx.params.category; + overview = ctx.params.overview ? true : false; + category = category === 'tech' ? 'technews' : category; + } else if (ctx.params.category) { + overview = true; + } const rootUrl = 'https://readhub.cn'; const apiRootUrl = 'https://api.readhub.cn'; @@ -35,14 +43,14 @@ module.exports = async (ctx) => { const items = await Promise.all( list.map((item) => - ctx.cache.tryGet(item.id, async () => { + ctx.cache.tryGet(item.id + overview, async () => { if (item.hasInstantView || category === 'daily') { const { data } = await got({ method: 'get', url: `${apiRootUrl}/topic/instantview?topicId=${item.id}`, }); - item.description = `访问原网址
${data.content}`; + item.description = `访问原网址
${!overview ? data.content : ''}`; } if (isNaN(item.id)) { @@ -51,6 +59,10 @@ module.exports = async (ctx) => { url: `${apiRootUrl}/topic/${item.id}`, }); + if (data.summary && overview) { + item.description += `${data.summary}
`; + } + if (data.newsArray) { item.description += '
媒体报道