add 西祠胡同 (#1762)

close #1308
This commit is contained in:
Chenyang Shi
2019-03-18 15:09:42 +08:00
committed by DIYgod
parent 9fe5497c40
commit ff821f201f
3 changed files with 56 additions and 0 deletions

View File

@@ -3178,6 +3178,16 @@ type 为 all 时category 参数不支持 cost 和 free
<route name="用户" author="SettingDust" example="/uraaka-joshi/_rrwq" path="/uraaka-joshi/:id" :paramsDesc="['用户名']"/>
### 西祠胡同
<route name="频道" author="LogicJake" example="/xici" path="/xici/:id?" :paramsDesc="['频道id默认为首页推荐']">
| 首页推荐 | 民生 | 情感 | 亲子 |
| -------- | ---- | ---- | ---- |
| (空) | ms | qg | qz |
</route>
### 今日热榜
<route name="榜单" author="LogicJake" example="/tophub/Om4ejxvxEN" path="/tophub/:id" :paramsDesc="['榜单id可在 URL 中找到']"/>

View File

@@ -1150,6 +1150,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('/xici/:id?', require('./routes/xici'));
// 今日热榜
router.get('/tophub/:id', require('./routes/tophub'));

43
lib/routes/xici/index.js Normal file
View File

@@ -0,0 +1,43 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const url = require('url');
const host = 'http://www.xici.net/t/';
module.exports = async (ctx) => {
const id = ctx.params.id || '..';
const link = url.resolve(host, id);
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const title = $('a.actived').text();
const out = $('ul.feed-list li[data-score]')
.slice(0, 10)
.map(function() {
const info = {
title: $(this)
.find('div.title a')
.text(),
link:
'http:' +
$(this)
.find('div.title a')
.attr('href'),
pubDate: $(this)
.find('span.time')
.attr('data-timeago'),
author: $(this)
.find('a.board-link')
.text(),
};
return info;
})
.get();
ctx.state.data = {
title: `${title}-西祠胡同`,
link: link,
item: out,
};
};