feat(route): add Foresight News article (#9295)

This commit is contained in:
Ethan Shen 2022-03-11 00:50:57 +08:00 committed by GitHub
parent 3965da8765
commit b7df26724e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -473,6 +473,18 @@ Country
<Route author="nczitzk" example="/foresightnews" path="/foresightnews"/>
### 文章
<Route author="nczitzk" example="/foresightnews/article" path="/foresightnews/article">
::: tip 提示
**文章** 来自 **首页** 时间流,并筛除 **首页** 时间流中的 **快讯** 获得,所以 `limit` 参数不能按预期返回指定数目的文章。
:::
</Route>
### 快讯
<Route author="nczitzk" example="/foresightnews/news" path="/foresightnews/news"/>

View File

@ -3,10 +3,14 @@ const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const categories = {
article: {
'': {
id: 'feed',
title: '首页',
},
article: {
id: 'feed',
title: '文章',
},
news: {
id: 'news',
title: '快讯',
@ -18,7 +22,7 @@ const categories = {
};
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'article';
const category = ctx.params.category ?? '';
const id = ctx.params.id ?? '1';
const rootUrl = 'https://foresightnews.pro';
@ -51,6 +55,10 @@ module.exports = async (ctx) => {
}
);
if (category === 'article') {
items = items.filter((item) => item.type === 'article');
}
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {

View File

@ -1,4 +1,5 @@
module.exports = {
'/': ['nczitzk'],
'/article': ['nczitzk'],
'/column/:id': ['nczitzk'],
'/news': ['nczitzk'],

View File

@ -6,6 +6,12 @@ module.exports = {
title: '首页',
docs: 'https://docs.rsshub.app/new-media.html#foresight-news-shou-ye',
source: ['/article', '/'],
target: '/foresightnews',
},
{
title: '文章',
docs: 'https://docs.rsshub.app/new-media.html#foresight-news-wen-zhang',
source: ['/article', '/'],
target: '/foresightnews/article',
},
{