fix(route): readhub add abstract (#9207)

* fix(route): add abstract

* fix(route): add an optional parameter to control show fulltext or overview
This commit is contained in:
Fatpandac 2022-02-28 20:44:10 +08:00 committed by GitHub
parent ef2e78f546
commit a48ec3cd82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 10 deletions

View File

@ -1064,7 +1064,7 @@ IPFS 网关有可能失效,那时候换成其他网关。
### 分类
<Route author="WhiteWorld nczitzk" example="/readhub" path="/readhub/:category?" :paramsDesc="['分类,见下表,默认为热门话题']">
<Route author="WhiteWorld nczitzk Fatpandac" example="/readhub" path="/readhub/:category?/:overview?" :paramsDesc="['分类,见下表,默认为热门话题', '获取概述,任意值获取概述,默认为不获取']">
| 热门话题 | 科技动态 | 技术资讯 | 区块链快讯 | 每日早报 |
| ----- | ---- | ---- | ---------- | ----- |

View File

@ -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 = `<a href="${data.url}">访问原网址</a><br>${data.content}`;
item.description = `<a href="${data.url}">访问原网址</a><br>${!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}<hr>`;
}
if (data.newsArray) {
item.description += '<br><b>媒体报道</b><ul>';

View File

@ -1,3 +1,3 @@
module.export = {
'/:category?': ['WhiteWorld', 'nczitzk'],
'/:category?/:overview?': ['WhiteWorld', 'nczitzk', 'Fatpandac'],
};

View File

@ -5,8 +5,8 @@ module.exports = {
{
title: '分类',
docs: 'https://docs.rsshub.app/new-media.html#readhub',
source: '/',
target: '/readhub',
source: ['/', '/:category'],
target: (params) => `/readhub/${params.category ? params.category : ''}`,
},
],
},

View File

@ -1,6 +1,6 @@
module.exports = (router) => {
// deprecated
router.get('/category/:category?', require('./index'));
router.get('/category/:category?/:overview?', require('./index'));
router.get('/:category?', require('./index'));
router.get('/:category?/:overview?', require('./index'));
};