mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): add 华人头条 (#7936)
* feat(route): add 华人头条 * fix: add timezone * refactor: migrate to v2 Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
@@ -64,6 +64,34 @@ pageClass: routes
|
||||
|
||||
<Route author="xyqfer kt286" example="/36kr/search/article/ofo" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
|
||||
## 52hrtt 华人头条
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="nczitzk" example="/52hrtt/global" path="/52hrtt/:area?/:type?" :paramsDesc="['地区,默认为全球', '分类,默认为新闻']">
|
||||
|
||||
地区和分类皆可在浏览器地址栏中找到,下面是一个例子。
|
||||
|
||||
访问华人头条全球站的国际分类,会跳转到 <https://www.52hrtt.com/global/n/w?infoTypeId=A1459145516533>。其中 `global` 即为 **全球** 对应的地区代码,`A1459145516533` 即为 **国际** 对应的分类代码。
|
||||
|
||||
</Route>
|
||||
|
||||
### 专题
|
||||
|
||||
<Route author="nczitzk" example="/52hrtt/symposium/F1626082387819" path="/52hrtt/symposium/:id?/:classId?" :paramsDesc="['专题 id', '子分类 id']">
|
||||
|
||||
专题 id 和 子分类 id 皆可在浏览器地址栏中找到,下面是一个例子。
|
||||
|
||||
访问 “邱毅看平潭” 专题,会跳转到 <https://www.52hrtt.com/global/n/w/symposium/F1626082387819>。其中 `F1626082387819` 即为 **专题 id** 对应的地区代码。
|
||||
|
||||
::: tip 提示
|
||||
|
||||
更多的专题可以点击 [这里](https://www.52hrtt.com/global/n/w/symposium)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 9To5
|
||||
|
||||
### 9To5 分站
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const area = ctx.params.area ?? 'global';
|
||||
const type = ctx.params.type ?? '';
|
||||
|
||||
const rootUrl = 'https://www.52hrtt.com';
|
||||
const currentUrl = `${rootUrl}/${area}/n/w${type ? `?infoTypeId=${type}` : ''}`;
|
||||
const apiUrl = `${rootUrl}/s/webapi/${area}/n/w${type ? `?infoTypeId=${type}` : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const titleResponse = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(titleResponse.data);
|
||||
|
||||
const list = response.data.data.infosMap.infoList
|
||||
.filter((item) => item.infoTitle)
|
||||
.map((item) => ({
|
||||
title: item.infoTitle,
|
||||
author: item.quoteFrom,
|
||||
pubDate: timezone(parseDate(item.infoStartTime), +8),
|
||||
link: `${rootUrl}/${area}/n/w/info/${item.infoCentreId}`,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.info-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${response.data.data.area.areaName} - ${$('.router-link-active').eq(0).text()} - 华人头条`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
'/symposium/:id?/:classId?': ['nczitzk'],
|
||||
'/:area?/:type?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
'52hrtt.com': {
|
||||
_name: '52hrtt 华人头条',
|
||||
'.': [
|
||||
{
|
||||
title: '新闻',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#_52hrtt-hua-ren-tou-tiao',
|
||||
source: '/',
|
||||
target: (_params, url) => `/52hrtt/${new URL(url).searchParams.get('infoTypeId')}`,
|
||||
},
|
||||
{
|
||||
title: '专题',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#_52hrtt-hua-ren-tou-tiao',
|
||||
source: '/global/n/w/symposium/:id',
|
||||
target: '/52hrtt/symposium/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/symposium/:id?/:classId?', require('./symposium'));
|
||||
router.get('/:area?/:type?', require('./'));
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id ?? '';
|
||||
const classId = ctx.params.classId ?? '';
|
||||
|
||||
const rootUrl = 'https://www.52hrtt.com';
|
||||
const currentUrl = `${rootUrl}/global/n/w/symposium/${id}`;
|
||||
const apiUrl = `${rootUrl}/s/webapi/global/symposium/getInfoList?symposiumId=${id}${classId ? `&symposiumclassId=${classId}` : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const titleResponse = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(titleResponse.data);
|
||||
|
||||
const list = response.data.data
|
||||
.filter((item) => item.infoTitle)
|
||||
.map((item) => ({
|
||||
title: item.infoTitle,
|
||||
author: item.quoteFrom,
|
||||
pubDate: timezone(parseDate(item.infoStartTime), +8),
|
||||
link: `${rootUrl}/global/n/w/info/${item.infoCentreId}`,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.info-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user