Skip to content

Commit

Permalink
feat(route): add xkb 新快报(新快网) (DIYgod#12134)
Browse files Browse the repository at this point in the history
* feat(route): add xkb 新快报(新快网)

* fix(route): fix 新快报

* fix(route): fix 新快报

* fix: radar domain

---------
  • Loading branch information
TimWu007 authored Mar 20, 2023
1 parent c22b0c1 commit 09c1dc1
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

## 新蓝网(浙江广播电视集团)

### 浙江新闻联播
Expand Down
54 changes: 54 additions & 0 deletions lib/v2/xkb/index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/xkb/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:channel': ['TimWu007'],
};
13 changes: 13 additions & 0 deletions lib/v2/xkb/radar.js
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions lib/v2/xkb/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel', require('./index'));
};
3 changes: 3 additions & 0 deletions lib/v2/xkb/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{ if thumb }}
<img src="{{ thumb }}"><br>
{{ /if }}

0 comments on commit 09c1dc1

Please sign in to comment.