feat(route): add xkb 新快报(新快网) (#12134)

* feat(route): add xkb 新快报(新快网)

* fix(route): fix 新快报

* fix(route): fix 新快报

* fix: radar domain

---------
This commit is contained in:
Tim Wu 2023-03-21 00:37:13 +08:00 committed by GitHub
parent c22b0c12ec
commit 09c1dc14d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 0 deletions

View File

@ -2294,6 +2294,24 @@ category 对应的关键词有
<Route author="MisteryMonster" example="/bjnews/epaper/A" path="/bjnews/epaper/:cat" :paramsDesc="['新京报叠名:`A`,`B`,`C`,`D`, 特刊为`special`']"/>
## 新快报
### 新闻
<Route author="TimWu007" example="/xkb/350" path="/xkb/:channel" :paramsDesc="['栏目 ID点击对应栏目后在地址栏找到']">
常用栏目 ID
| 栏目名 | ID |
| ------ | --- |
| 首页 | 350 |
| 重点 | 359 |
| 广州 | 353 |
| 湾区 | 360 |
| 天下 | 355 |
</Route>
## 新蓝网(浙江广播电视集团)
### 浙江新闻联播

54
lib/v2/xkb/index.js Normal file
View File

@ -0,0 +1,54 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const channel = ctx.params.channel ?? 1;
const currentUrl = `https://www.xkb.com.cn/xkbapp/fundapi/article/api/articles?chnlId=${channel}&visibility=1&page=0&size=20&keyword=`;
const { data: response } = await got({
method: 'get',
url: currentUrl,
headers: {
siteId: '35',
},
});
const list = response.data
.filter((i) => i.contentUrl) // Remove "专题报道" (special report)
.map((item) => ({
title: item.listTitle,
description: art(path.join(__dirname, 'templates/description.art'), {
thumb: item.metaInfo.thumbnails[0],
}),
pubDate: timezone(parseDate(item.operTime), +8),
link: 'https://www.xkb.com.cn/#/detail?id=' + item.id,
contentUrl: item.contentUrl,
author: item.metaInfo.author,
chnlName: item.metaInfo.chnlName,
}));
let chnlName = '';
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.contentUrl, async () => {
const detailResponse = await got({
method: 'get',
url: item.contentUrl,
});
item.description += detailResponse.data.htmlContent ?? '';
chnlName = chnlName === '' ? item.chnlName : chnlName;
return item;
})
)
);
ctx.state.data = {
title: `新快报新快网 - ${chnlName}`,
link: `https://www.xkb.com.cn/#/home?id=${channel}`,
item: items,
};
};

3
lib/v2/xkb/maintainer.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
'/:channel': ['TimWu007'],
};

13
lib/v2/xkb/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'xkb.com.cn': {
_name: '新快报',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/traditional-media.html#xin-kuai-bao',
source: ['/'],
target: (_, url) => `/xkb/${new URL(url).hash.match(/\?id=(\d+)/)[1]}`,
},
],
},
};

3
lib/v2/xkb/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel', require('./index'));
};

View File

@ -0,0 +1,3 @@
{{ if thumb }}
<img src="{{ thumb }}"><br>
{{ /if }}