diff --git a/lib/routes/readhub/category.js b/lib/routes/readhub/category.js
index 65aa7cfd6..8d3f20605 100644
--- a/lib/routes/readhub/category.js
+++ b/lib/routes/readhub/category.js
@@ -1,25 +1,32 @@
const axios = require('../../utils/axios');
+const dayjs = require('dayjs');
module.exports = async (ctx) => {
const category = ctx.params.category;
let title;
+ let link;
let path = category;
switch (category) {
case 'topic':
title = '热门话题';
+ link = 'https://readhub.cn/topics';
break;
case 'news':
title = '科技动态';
+ link = 'https://readhub.cn/news';
break;
case 'technews':
title = '开发者资讯';
+ link = 'https://readhub.cn/tech';
break;
case 'blockchain':
title = '区块链快讯';
+ link = 'https://readhub.cn/blockchain';
break;
case 'daily':
title = '每日早报';
+ link = 'https://readhub.cn/daily';
break;
default:
break;
@@ -29,22 +36,63 @@ module.exports = async (ctx) => {
path = 'topic/daily';
}
- const response = await axios({
+ const {
+ data: { data },
+ } = await axios({
method: 'get',
url: `https://api.readhub.cn/${path}`,
});
- const data = response.data;
+ const promises = data.map(async (news) => {
+ const id = news.id;
+ if (category === 'topic' || category === 'daily') {
+ const link = `https://readhub.cn/topic/${id}`;
+ const cache = ctx.cache.get(link);
+ if (cache) {
+ return cache;
+ }
+ const { data } = await axios.get(`https://api.readhub.cn/topic/${id}`);
+ let description = data.summary;
+ if (data.newsArray) {
+ description += '
媒体报道:';
+ for (const one of data.newsArray) {
+ description += `
${dayjs(new Date(one.publishDate)).format('YY-MM-DD')} ${one.siteName}: ${one.title}`;
+ }
+ }
+ if (data.timeline && data.timeline.topics) {
+ let type = '相关事件';
+ if (data.timeline.commonEntities && data.timeline.commonEntities.length > 0) {
+ type = '事件追踪';
+ }
+ description += `
${type}:`;
+ for (const one of data.timeline.topics) {
+ description += `
${dayjs(new Date(one.createdAt)).format('YY-MM-DD')} ${one.title.trim()}`;
+ }
+ }
+ const item = {
+ title: data.title,
+ description: description.replace(new RegExp('\n', 'g'), '
'),
+ pubDate: data.publishDate,
+ guid: id,
+ link,
+ };
+ ctx.cache.set(link, description);
+ return item;
+ } else {
+ const description = news.summaryAuto || news.summary || news.title;
+ return {
+ title: news.title,
+ description: description.replace(new RegExp('\n', 'g'), '
'),
+ pubDate: news.publishDate,
+ guid: id,
+ link: news.url || news.mobileUrl,
+ };
+ }
+ });
ctx.state.data = {
title: `Readhub-${title}`,
- link: 'https://readhub.cn',
- item: data.data.map((item) => ({
- title: item.title,
- pubDate: new Date(item.publishDate || Date.now()).toUTCString(),
- description: item.summary || item.title,
- guid: `/${category}/${item.id}`,
- link: category === 'daily' ? `https://readhub.cn/topic/${item.id}` : item.url || item.newsArray[0].url,
- })),
+ link,
+ item: await Promise.all(promises),
};
};