From 6c3eb6d0a844208e0ff91d2c5d5b2e69829342aa Mon Sep 17 00:00:00 2001 From: Yu Fan <41051953+FuryMartin@users.noreply.github.com> Date: Fri, 24 Nov 2023 22:35:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=87=8F=E5=AD=90?= =?UTF-8?q?=E4=BD=8D=20(#13874)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 量子位 * Initial commit * fix(route): replace xml2js with rss-parser * Apply suggestions from code review * docs: move to new-media --------- --- lib/v2/qbitai/category.js | 27 +++++++++++++++++++++++++++ lib/v2/qbitai/maintainer.js | 4 ++++ lib/v2/qbitai/radar.js | 19 +++++++++++++++++++ lib/v2/qbitai/router.js | 4 ++++ lib/v2/qbitai/tag.js | 27 +++++++++++++++++++++++++++ website/docs/routes/new-media.mdx | 14 ++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 lib/v2/qbitai/category.js create mode 100644 lib/v2/qbitai/maintainer.js create mode 100644 lib/v2/qbitai/radar.js create mode 100644 lib/v2/qbitai/router.js create mode 100644 lib/v2/qbitai/tag.js diff --git a/lib/v2/qbitai/category.js b/lib/v2/qbitai/category.js new file mode 100644 index 000000000..291bd9b1a --- /dev/null +++ b/lib/v2/qbitai/category.js @@ -0,0 +1,27 @@ +const parser = require('@/utils/rss-parser'); + +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category } = ctx.params; + const link = encodeURI(`https://www.qbitai.com/category/${category}/feed`); + const feed = await parser.parseURL(link); + + const items = feed.items.map((item) => ({ + title: item.title, + pubDate: parseDate(item.pubDate), + link: item.link, + author: '量子位', + category: item.categories, + description: item['content:encoded'], + })); + + ctx.state.data = { + // 源标题 + title: `量子位-${category}`, + // 源链接 + link: `https://www.qbitai.com/category/${category}`, + // 源文章 + item: items, + }; +}; diff --git a/lib/v2/qbitai/maintainer.js b/lib/v2/qbitai/maintainer.js new file mode 100644 index 000000000..26f19df2a --- /dev/null +++ b/lib/v2/qbitai/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/category/:category': ['FuryMartin'], + '/tag/:tag': ['FuryMartin'], +}; diff --git a/lib/v2/qbitai/radar.js b/lib/v2/qbitai/radar.js new file mode 100644 index 000000000..ec46f915a --- /dev/null +++ b/lib/v2/qbitai/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'qbitai.com': { + _name: '量子位', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/routes/new-media#liang-zi-wei', + source: ['/category/:category'], + target: '/qbitai/category/:category', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/routes/new-media#liang-zi-wei', + source: ['/tag/:tag'], + target: '/qbitai/tag/:tag', + }, + ], + }, +}; diff --git a/lib/v2/qbitai/router.js b/lib/v2/qbitai/router.js new file mode 100644 index 000000000..511ccb2e3 --- /dev/null +++ b/lib/v2/qbitai/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/category/:category', require('./category')); + router.get('/tag/:tag', require('./tag')); +}; diff --git a/lib/v2/qbitai/tag.js b/lib/v2/qbitai/tag.js new file mode 100644 index 000000000..cd0fc9e2e --- /dev/null +++ b/lib/v2/qbitai/tag.js @@ -0,0 +1,27 @@ +const parser = require('@/utils/rss-parser'); + +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { tag } = ctx.params; + const link = encodeURI(`https://www.qbitai.com/tag/${tag}/feed`); + const feed = await parser.parseURL(link); + + const items = feed.items.map((item) => ({ + title: item.title, + pubDate: parseDate(item.pubDate), + link: item.link, + author: '量子位', + category: item.categories, + description: item['content:encoded'], + })); + + ctx.state.data = { + // 源标题 + title: `量子位-${tag}`, + // 源链接 + link: `https://www.qbitai.com/tag/${tag}`, + // 源文章 + item: items, + }; +}; diff --git a/website/docs/routes/new-media.mdx b/website/docs/routes/new-media.mdx index 189025c53..376a70ef5 100644 --- a/website/docs/routes/new-media.mdx +++ b/website/docs/routes/new-media.mdx @@ -4177,6 +4177,20 @@ column 为 third 时可选的 category: +## 量子位 {#liang-zi-wei} + +### 分类 {#liang-zi-wei-fen-lei} + + + +| 资讯 | 数码 | 智能车 | 智库 | 活动 | +| ---- | ---- | ------ | ---- | ---- | +| 资讯 | ebandeng | auto | zhiku | huodong | + +### 标签 {#liang-zi-wei-biao-qian} + + + ## 留园网 {#liu-yuan-wang} ### 分站 {#liu-yuan-wang-fen-zhan}