mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
feat(route): 环球网 (#9580)
* feat(route): 环球网 * feat(route): 环球网 加入通用参数limit限制条数及格式调整 Co-authored-by: alex <yuxin2@mgtv.com>
This commit is contained in:
@@ -942,6 +942,19 @@ Type 栏目:
|
||||
|
||||
</Route>
|
||||
|
||||
## 环球网
|
||||
|
||||
### 分类
|
||||
|
||||
<Route author="yuxinliu-alex" example="/huanqiu/news/china" path="/huanqiu/news/:category?" :paramsDesc="['类别,可以使用二级域名作为参数,默认为:china']">
|
||||
|
||||
|
||||
| 国内新闻 | 国际新闻 | 军事 | 台海 | 评论 |
|
||||
|-------| ----------- | -------- |---------------|---------|
|
||||
| china | world | mil | taiwai| opinion |
|
||||
|
||||
</Route>
|
||||
|
||||
## 极客公园
|
||||
|
||||
### 全球快讯
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
function getKeysRecursive(dic, key, attr, array) {
|
||||
Object.values(dic).forEach((v) => {
|
||||
if (v[key] !== undefined) {
|
||||
getKeysRecursive(v[key], key, attr, array);
|
||||
} else {
|
||||
array.push(v[attr]);
|
||||
}
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'china';
|
||||
const host = 'https://' + category + '.huanqiu.com';
|
||||
|
||||
const resp = await got({
|
||||
method: 'get',
|
||||
url: host.concat('/api/channel_pc'),
|
||||
}).json();
|
||||
const name = getKeysRecursive(resp.children, 'children', 'domain_name', [])[0];
|
||||
|
||||
const nodes = getKeysRecursive(resp.children, 'children', 'node', [])
|
||||
.map((x) => '"' + x + '"')
|
||||
.join();
|
||||
const req = await got({
|
||||
method: 'get',
|
||||
url: host.concat('/api/list?node=') + nodes.concat(`&offset=0&limit=${ctx.query.limit ?? 20}`),
|
||||
}).json();
|
||||
|
||||
let items = req.list
|
||||
.filter((item) => item.aid)
|
||||
.map((item) => ({
|
||||
link: host.concat('/article/' + item.aid),
|
||||
title: item.title,
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
item.description = content('article').html();
|
||||
item.author = content('span', '.source').text();
|
||||
item.pubDate = timezone(parseDate(content('p.time').text()), +8);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${name} - 环球网`,
|
||||
link: host,
|
||||
description: '环球网',
|
||||
language: 'zh-cn',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/news/:category?': ['yuxinliu-alex'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'huanqiu.com': {
|
||||
_name: '环球网',
|
||||
'.': [
|
||||
{
|
||||
title: '分类',
|
||||
docs: 'https://docs.rsshub.app/traditional-media.html#huan-qiu',
|
||||
source: '/',
|
||||
target: '/news/huanqiu/:category?',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/news/:category?', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user