diff --git a/lib/routes/readhub/category.js b/lib/routes/readhub/category.js
index c1922d9e5..0dcf8d468 100644
--- a/lib/routes/readhub/category.js
+++ b/lib/routes/readhub/category.js
@@ -43,56 +43,60 @@ module.exports = async (ctx) => {
url: `https://api.readhub.cn/${path}`,
});
- const promises = data.map(async (news) => {
- const id = news.id;
- if (category === 'topic' || category === 'daily') {
- const link = `https://readhub.cn/topic/${id}`;
- const cache = await 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}`;
+ const out = await Promise.all(
+ data.map(async (news) => {
+ const id = news.id;
+ let item;
+ if (category === 'topic' || category === 'daily') {
+ const link = `https://readhub.cn/topic/${id}`;
+ const cache = await ctx.cache.get(link);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
}
- }
- if (data.timeline && data.timeline.topics) {
- let type = '相关事件';
- if (data.timeline.commonEntities && data.timeline.commonEntities.length > 0) {
- type = '事件追踪';
+ 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}`;
+ }
}
- description += `
${type}:`;
- for (const one of data.timeline.topics) {
- description += `
${dayjs(new Date(one.createdAt)).format('YY-MM-DD')} ${one.title.trim()}`;
+ 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()}`;
+ }
}
+ item = {
+ title: data.title,
+ description: description.replace(new RegExp('\n', 'g'), '
'),
+ pubDate: data.publishDate,
+ guid: id,
+ link,
+ };
+ } else {
+ const description = news.summaryAuto || news.summary || news.title;
+ item = {
+ title: news.title,
+ description: description.replace(new RegExp('\n', 'g'), '
'),
+ pubDate: news.publishDate,
+ guid: id,
+ link: news.url || news.mobileUrl,
+ };
}
- const item = {
- title: data.title,
- description: description.replace(new RegExp('\n', 'g'), '
'),
- pubDate: data.publishDate,
- guid: id,
- link,
- };
- await ctx.cache.set(link, description, 24 * 60 * 60);
- 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,
- };
- }
- });
+
+ await ctx.cache.set(link, JSON.stringify(item), 24 * 60 * 60);
+ return Promise.resolve(item);
+ })
+ );
ctx.state.data = {
- title: `Readhub-${title}`,
+ title: `Readhub - ${title}`,
link,
- item: await Promise.all(promises),
+ item: out,
};
};