feat(route): add 量子位 (#13874)

* feat(route): add 量子位

* Initial commit

* fix(route): replace xml2js with rss-parser

* Apply suggestions from code review

* docs: move to new-media

---------
This commit is contained in:
Yu Fan 2023-11-24 22:35:14 +08:00 committed by GitHub
parent 7d71b57036
commit 6c3eb6d0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 95 additions and 0 deletions

27
lib/v2/qbitai/category.js Normal file
View File

@ -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,
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
'/category/:category': ['FuryMartin'],
'/tag/:tag': ['FuryMartin'],
};

19
lib/v2/qbitai/radar.js Normal file
View File

@ -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',
},
],
},
};

4
lib/v2/qbitai/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/category/:category', require('./category'));
router.get('/tag/:tag', require('./tag'));
};

27
lib/v2/qbitai/tag.js Normal file
View File

@ -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,
};
};

View File

@ -4177,6 +4177,20 @@ column 为 third 时可选的 category:
</Route>
## 量子位 {#liang-zi-wei}
### 分类 {#liang-zi-wei-fen-lei}
<Route author="FuryMartin" example="/qbitai/category/资讯" path="/qbitai/category/:category" paramsDesc={['分类名,见下表']} />
| 资讯 | 数码 | 智能车 | 智库 | 活动 |
| ---- | ---- | ------ | ---- | ---- |
| 资讯 | ebandeng | auto | zhiku | huodong |
### 标签 {#liang-zi-wei-biao-qian}
<Route author="FuryMartin" example="/qbitai/tag/大语言模型" path="/qbitai/tag/:tag" paramsDesc={['标签名']} />
## 留园网 {#liu-yuan-wang}
### 分站 {#liu-yuan-wang-fen-zhan}