Skip to content

Commit

Permalink
feat(route): add tophub list 将榜单条目集合到一个列表中,可避免推送大量条目,更符合阅读习惯且有热度排序 (#…
Browse files Browse the repository at this point in the history
…14056)

* feat(route): add fxiaoke.com blog

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/fxiaoke/crm.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* gen exact pubdate

* feat(route): add tophub list

* fix: guid

* fix: use art to render rank

---------
  • Loading branch information
Jack Bryant authored Dec 18, 2023
1 parent 4cf17c0 commit 92c8936
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/v2/tophub/list.js
Original file line number Diff line number Diff line change
@@ -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,
},
],
};
};
1 change: 1 addition & 0 deletions lib/v2/tophub/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/:id': ['LogicJake'],
'/list/:id': ['akynazh'],
};
6 changes: 6 additions & 0 deletions lib/v2/tophub/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/tophub/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = (router) => {
router.get('/:id', require('./'));
router.get('/list/:id', require('./list'));
};
22 changes: 22 additions & 0 deletions lib/v2/tophub/templates/rank.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th>排名</th>
<th>标题</th>
<th>热度</th>
</tr>
</thead>
<tbody>
{{each items}}
<tr>
<td>{{ $index + 1 }}</td>
<td>
<a href="{{ $value.link }}">
{{ $value.title }}
</a>
</td>
<td>{{ $value.heatRate }}</td>
</tr>
{{/each}}
</tbody>
</table>
8 changes: 8 additions & 0 deletions website/docs/routes/new-media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,14 @@ IPFS 网关有可能失效,那时候换成其他网关。

<Route author="LogicJake" example="/tophub/Om4ejxvxEN" path="/tophub/:id" paramsDesc={['榜单id,可在 URL 中找到']} />

### 榜单列表 {#jin-ri-re-bang-bang-dan-lie-biao}

<Route author="akynazh" example="/tophub/list/Om4ejxvxEN" path="/tophub/list/:id" paramsDesc={['榜单id,可在 URL 中找到']} />

:::tip
将榜单条目集合到一个列表中,可避免推送大量条目,更符合阅读习惯且有热度排序,推荐使用。
:::

## 今日头条 {#jin-ri-tou-tiao}

### 关键词 {#jin-ri-tou-tiao-guan-jian-ci}
Expand Down

0 comments on commit 92c8936

Please sign in to comment.