add 今日热榜 (#1741)

close #1734
This commit is contained in:
Chenyang Shi
2019-03-13 12:07:30 +08:00
committed by DIYgod
parent 1d957fcf30
commit 909b0fdf4d
3 changed files with 41 additions and 0 deletions
+4
View File
@@ -3169,3 +3169,7 @@ type 为 all 时,category 参数不支持 cost 和 free
<route name="主页" author="SettingDust" example="/uraaka-joshi" path="/uraaka-joshi"/>
<route name="用户" author="SettingDust" example="/uraaka-joshi/_rrwq" path="/uraaka-joshi/:id" :paramsDesc="['用户名']"/>
### 今日热榜
<route name="榜单" author="LogicJake" example="/tophub/Om4ejxvxEN" path="/tophub/:id" :paramsDesc="['榜单id,可在 URL 中找到']"/>
+3
View File
@@ -1145,6 +1145,9 @@ router.get('/blogs/jingwei.link', require('./routes/blogs/jingwei_link'));
router.get('/uraaka-joshi', require('./routes/uraaka-joshi/uraaka-joshi'));
router.get('/uraaka-joshi/:id', require('./routes/uraaka-joshi/uraaka-joshi-user'));
// 今日热榜
router.get('/tophub/:id', require('./routes/tophub'));
// 游戏时光
router.get('/vgtime/news', require('./routes/vgtime/news.js'));
router.get('/vgtime/release', require('./routes/vgtime/release'));
+34
View File
@@ -0,0 +1,34 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const link = `https://tophub.today/n/${id}`;
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('div.Xc-ec-L.b-L')
.text()
.trim();
const out = $('div.Zd-p-Sc > div:nth-child(1) tr')
.map(function() {
const info = {
title: $(this)
.find('td.al a')
.text(),
link: $(this)
.find('td.al a')
.attr('href'),
};
return info;
})
.get();
ctx.state.data = {
title: title,
link: link,
item: out,
};
};