diff --git a/lib/v2/tophub/list.js b/lib/v2/tophub/list.js new file mode 100644 index 000000000..7c56b40f2 --- /dev/null +++ b/lib/v2/tophub/list.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const config = require('@/config').value; +const path = require('path'); +const { art } = require('@/utils/render'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `https://tophub.today/n/${id}`; + const response = await got.get(link, { + headers: { + Referer: 'https://tophub.today', + Cookie: config.tophub.cookie, + }, + }); + const $ = cheerio.load(response.data); + const title = $('div.Xc-ec-L.b-L').text().trim(); + const items = $('div.Zd-p-Sc > div:nth-child(1) tr') + .toArray() + .map((e) => ({ + title: $(e).find('td.al a').text().trim(), + link: $(e).find('td.al a').attr('href'), + heatRate: $(e).find('td:nth-child(3)').text().trim(), + })); + const combinedTitles = items.map((item) => item.title).join(''); + const renderRank = art(path.join(__dirname, 'templates/rank.art'), { items }); + + ctx.state.data = { + title, + link, + item: [ + { + title, + link, + description: renderRank, + guid: combinedTitles, + }, + ], + }; +}; diff --git a/lib/v2/tophub/maintainer.js b/lib/v2/tophub/maintainer.js index fdeacdedf..7d1aae186 100644 --- a/lib/v2/tophub/maintainer.js +++ b/lib/v2/tophub/maintainer.js @@ -1,3 +1,4 @@ module.exports = { '/:id': ['LogicJake'], + '/list/:id': ['akynazh'], }; diff --git a/lib/v2/tophub/radar.js b/lib/v2/tophub/radar.js index 0b0304224..37552bf63 100644 --- a/lib/v2/tophub/radar.js +++ b/lib/v2/tophub/radar.js @@ -8,6 +8,12 @@ module.exports = { source: ['/n/:id'], target: '/tophub/:id', }, + { + title: '榜单列表', + docs: 'https://docs.rsshub.app/routes/new-media#jin-ri-re-bang-bang-dan-lie-biao', + source: ['/n/:id'], + target: '/tophub/list/:id', + }, ], }, }; diff --git a/lib/v2/tophub/router.js b/lib/v2/tophub/router.js index b0440f0cd..93770c6b3 100644 --- a/lib/v2/tophub/router.js +++ b/lib/v2/tophub/router.js @@ -1,3 +1,4 @@ module.exports = (router) => { router.get('/:id', require('./')); + router.get('/list/:id', require('./list')); }; diff --git a/lib/v2/tophub/templates/rank.art b/lib/v2/tophub/templates/rank.art new file mode 100644 index 000000000..59e87d79d --- /dev/null +++ b/lib/v2/tophub/templates/rank.art @@ -0,0 +1,22 @@ +
| 排名 | +标题 | +热度 | +
|---|---|---|
| {{ $index + 1 }} | ++ + {{ $value.title }} + + | +{{ $value.heatRate }} | +