diff --git a/docs/traditional-media.md b/docs/traditional-media.md index b2d918408..d653ba89c 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -2294,6 +2294,24 @@ category 对应的关键词有 +## 新快报 + +### 新闻 + + + +常用栏目 ID: + +| 栏目名 | ID | +| ------ | --- | +| 首页 | 350 | +| 重点 | 359 | +| 广州 | 353 | +| 湾区 | 360 | +| 天下 | 355 | + + + ## 新蓝网(浙江广播电视集团) ### 浙江新闻联播 diff --git a/lib/v2/xkb/index.js b/lib/v2/xkb/index.js new file mode 100644 index 000000000..2e53134f2 --- /dev/null +++ b/lib/v2/xkb/index.js @@ -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, + }; +}; diff --git a/lib/v2/xkb/maintainer.js b/lib/v2/xkb/maintainer.js new file mode 100644 index 000000000..36c1a5ed9 --- /dev/null +++ b/lib/v2/xkb/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:channel': ['TimWu007'], +}; diff --git a/lib/v2/xkb/radar.js b/lib/v2/xkb/radar.js new file mode 100644 index 000000000..9f8cd2af9 --- /dev/null +++ b/lib/v2/xkb/radar.js @@ -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]}`, + }, + ], + }, +}; diff --git a/lib/v2/xkb/router.js b/lib/v2/xkb/router.js new file mode 100644 index 000000000..c4632ce7a --- /dev/null +++ b/lib/v2/xkb/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:channel', require('./index')); +}; diff --git a/lib/v2/xkb/templates/description.art b/lib/v2/xkb/templates/description.art new file mode 100644 index 000000000..2113e7063 --- /dev/null +++ b/lib/v2/xkb/templates/description.art @@ -0,0 +1,3 @@ +{{ if thumb }} +
+{{ /if }} \ No newline at end of file