后续 RSS (#872)

* 增加 puppeteer 依赖

* houxu
This commit is contained in:
fengkx 2018-10-14 16:33:36 +08:00 committed by DIYgod
parent ecb0fdc57e
commit 3707145428
3 changed files with 42 additions and 0 deletions

View File

@ -1851,3 +1851,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### 观止(每日一文)
<route name="观止" author="Andiedie" example="/guanzhi" path="/guanzhi"/>
### 后续
<route name="后续" author="fengkx" example="/houxu/events/38" path="/houxu/:type/:id" :paramsDesc="['类型', 'ID']"/>

View File

@ -625,6 +625,9 @@ router.get('/pediy/topic/:category?/:type?', require('./routes/pediy/topic'));
// 观止(每日一文)
router.get('/guanzhi', require('./routes/guanzhi/guanzhi'));
// 后续
router.get('/houxu/:type/:id', require('./routes/houxu/houxu'));
// 老司机
router.get('/laosiji/hot', require('./routes/laosiji/hot'));
router.get('/laosiji/feed', require('./routes/laosiji/feed'));

35
routes/houxu/houxu.js Normal file
View File

@ -0,0 +1,35 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { type, id } = ctx.params;
const baseUrl = `https://houxu.app/${type}/${id}`;
const res = await axios.get(baseUrl);
const data = res.data;
const $ = cheerio.load(data);
const list = $('section.threads > div').get();
const descriptionSelector = type === 'live' ? '.summary' : '.readable';
const out = list.map((item) => {
const each = $(item);
return {
title: each
.find('a')
.text()
.trim(),
description: each
.find(descriptionSelector)
.text()
.trim(),
link: each.find('a').attr('href'),
};
});
ctx.state.data = {
title: $('.large-title').text(),
description: $('title')
.text()
.trim(),
link: baseUrl,
item: out,
};
};