diff --git a/docs/new-media.md b/docs/new-media.md index 5cf3e9f33..3922e8cc0 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1545,6 +1545,23 @@ Supported sub-sites: +## zyw + +### 今日热榜 + + + +::: tip 提示 + +全部站点请见 [此处](https://hot.zyw.asia/#/list) + +::: + +| 哔哩哔哩 | 微博 | 知乎 | 36氪 | 百度 | 少数派 | IT之家 | 澎湃新闻 | 今日头条 | 百度贴吧 | 稀土掘金 | 腾讯新闻 | +| -------- | ---- | ---- | ---- | ---- | ------ | ------ | -------- | -------- | -------- | -------- | -------- | + + + ## 阿里研究院 ### 资讯 diff --git a/lib/v2/zyw/hot.js b/lib/v2/zyw/hot.js new file mode 100644 index 000000000..4f24ab45b --- /dev/null +++ b/lib/v2/zyw/hot.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const site = ctx.params.site ?? ''; + + const rootUrl = 'https://hot.zyw.asia'; + const apiRootUrl = 'https://api-hot.zyw.asia'; + + let response = await got({ + method: 'get', + url: rootUrl, + }); + + const jsUrl = `${rootUrl}${response.data.match(/crossorigin src="(\/assets\/index-\w+\.js)">/)[1]}`; + + response = await got({ + method: 'get', + url: jsUrl, + }); + + const sites = response.data + .match(/label:"(.*?)",value:"(.*?)",order/g) + .map((a) => { + const matches = a.match(/label:"(.*?)",value:"(.*?)"/); + return { + label: matches[1], + value: matches[2], + }; + }) + .filter((a) => (site ? a.label === site || a.value === site : true)); + + const currentUrl = `${rootUrl}${site ? `/#/list?type=${sites[0].value}` : ''}`; + + const items = []; + + await Promise.all( + sites.map(async (a) => { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/${a.value}`, + headers: { + referer: rootUrl, + }, + }); + + for (const d of detailResponse.data.data) { + items.push({ + link: d.url, + title: d.title, + description: d.desc, + }); + } + + return; + }) + ); + + ctx.state.data = { + title: `今日热榜${site ? ` - ${sites[0].label}` : ''}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/zyw/maintainer.js b/lib/v2/zyw/maintainer.js new file mode 100644 index 000000000..d57b3e6ff --- /dev/null +++ b/lib/v2/zyw/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/hot/:site?': ['nczitzk'], +}; diff --git a/lib/v2/zyw/radar.js b/lib/v2/zyw/radar.js new file mode 100644 index 000000000..ffa663f03 --- /dev/null +++ b/lib/v2/zyw/radar.js @@ -0,0 +1,16 @@ +module.exports = { + 'zyw.asia': { + _name: 'zyw', + hot: [ + { + title: '今日热榜', + docs: 'https://docs.rsshub.app/new-media.html#zyw-jin-ri-re-bang', + source: ['/'], + target: (params, url) => { + const matches = new URL(url).href.match(/type=(\w+)/); + return `/zyw/hot${matches ? `/${matches[1]}` : ''}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/zyw/router.js b/lib/v2/zyw/router.js new file mode 100644 index 000000000..2e0b77f1b --- /dev/null +++ b/lib/v2/zyw/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/hot/:site?', require('./hot')); +};