add 亲子王国 (#1769)

This commit is contained in:
Chenyang Shi 2019-03-18 15:17:36 +08:00 committed by DIYgod
parent 2bbceece4e
commit f83a3c8bf9
3 changed files with 68 additions and 0 deletions

View File

@ -3201,3 +3201,13 @@ type 为 all 时category 参数不支持 cost 和 free
### 今日热榜
<route name="榜单" author="LogicJake" example="/tophub/Om4ejxvxEN" path="/tophub/:id" :paramsDesc="['榜单id可在 URL 中找到']"/>
### 親子王國
<route name="板块" author="LogicJake" example="/babykingdom/19/view" path="/babykingdom/:id/:order?" :paramsDesc="['板块id可在 URL 中找到', '排序方式']">
| 发帖时间 | 回复/查看 | 查看 | 最后发表 | 热门 |
| -------- | --------- | ---- | -------- | ---- |
| dateline | reply | view | lastpost | heat |
</route>

View File

@ -1163,6 +1163,9 @@ router.get('/vgtime/release', require('./routes/vgtime/release'));
// MP4吧
router.get('/mp4ba/:param', require('./routes/mp4ba'));
// 親子王國
router.get('/babykingdom/:id/:order?', require('./routes/babykingdom'));
// 浙江工商大学
router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts'));
router.get('/zjgsu/gsgg', require('./routes/universities/zjgsu/gsgg/scripts'));

View File

@ -0,0 +1,55 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'https://www.baby-kingdom.com';
module.exports = async (ctx) => {
const id = ctx.params.id;
const order = ctx.params.order;
let link = `https://www.baby-kingdom.com/forum.php?mod=forumdisplay&fid=${id}`;
if (order === 'dateline') {
link += '&filter=author&orderby=dateline';
} else if (order === 'reply') {
link += '&filter=reply&orderby=replies';
} else if (order === 'view') {
link += '&filter=reply&orderby=views';
} else if (order === 'lastpost') {
link += '&filter=lastpost&orderby=lastpost';
} else if (order === 'heat') {
link += '&filter=heat&orderby=heats';
}
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('h1.xs2 a').text();
const out = $('tbody[id^="normalthread"]')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('td:nth-child(2) > a:nth-child(1)')
.text(),
link: url.resolve(
host,
$(this)
.find('td:nth-child(2) > a:nth-child(1)')
.attr('href')
),
author: $(this)
.find('td.by.by_author cite a')
.text(),
};
return info;
})
.get();
ctx.state.data = {
title: `${title}-親子王國`,
link: link,
item: out,
};
};