From b7df26724ec2fbf814f109a5fbac5803a944d42e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 11 Mar 2022 00:50:57 +0800 Subject: [PATCH] feat(route): add Foresight News article (#9295) --- docs/new-media.md | 12 ++++++++++++ lib/v2/foresightnews/index.js | 12 ++++++++++-- lib/v2/foresightnews/maintainer.js | 1 + lib/v2/foresightnews/radar.js | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/new-media.md b/docs/new-media.md index 1a40ad946..e3eb29094 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -473,6 +473,18 @@ Country +### 文章 + + + +::: tip 提示 + +**文章** 来自 **首页** 时间流,并筛除 **首页** 时间流中的 **快讯** 获得,所以 `limit` 参数不能按预期返回指定数目的文章。 + +::: + + + ### 快讯 diff --git a/lib/v2/foresightnews/index.js b/lib/v2/foresightnews/index.js index 10a5cc4c1..d1d782624 100644 --- a/lib/v2/foresightnews/index.js +++ b/lib/v2/foresightnews/index.js @@ -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 () => { diff --git a/lib/v2/foresightnews/maintainer.js b/lib/v2/foresightnews/maintainer.js index 45a92931b..41ccd6392 100644 --- a/lib/v2/foresightnews/maintainer.js +++ b/lib/v2/foresightnews/maintainer.js @@ -1,4 +1,5 @@ module.exports = { + '/': ['nczitzk'], '/article': ['nczitzk'], '/column/:id': ['nczitzk'], '/news': ['nczitzk'], diff --git a/lib/v2/foresightnews/radar.js b/lib/v2/foresightnews/radar.js index 49f0da125..0c5264950 100644 --- a/lib/v2/foresightnews/radar.js +++ b/lib/v2/foresightnews/radar.js @@ -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', }, {