update houxu routers. (#1583)

- 修复了原有路由中标题格式错乱的问题,并将原路由移动到`/houxu/live/:id`。
- 添加了可以在live中对时间线筛选的可选参数`timeline`。
- 移除对单个专栏的订阅。专栏内容几乎不会更新,所以订阅单个专栏没有意义,故而移除。
- 添加了`/houxu/events`路由。当有新的专栏推出时可以推送。
- 添加了`/houxu/lives`路由。当有新的lives推出时可以推送。
This commit is contained in:
ciaran
2019-02-20 11:02:30 +08:00
committed by DIYgod
parent 52c5b1270a
commit a118a56615
6 changed files with 165 additions and 37 deletions
+11 -1
View File
@@ -2801,7 +2801,17 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
### 后续
<route name="事件" author="fengkx" example="/houxu/events/38" path="/houxu/:type/:id" :paramsDesc="['类型', 'ID']"/>
<route name="Live" author="Ciaran" example="/houxu/lives/5/original" path="/houxu/lives/:id/:timeline?" :paramsDesc="['Live ID', '时间线筛选条件。默认为all。']">
| 全部 | 原创 | 精选 |
| ---- | -------- | -------- |
| all | original | featured |
</route>
<route name="最新Live" author="Ciaran" example="/houxu/new_lives/new" path="/houxu/new_lives/:type" :paramsDesc="['类型。实时进展`realtime` 或 最近关注`new`']" />
<route name="最新专栏" author="Ciaran" example="/houxu/new_events" path="/houxu/new_events"/>
### 老司机
+3 -1
View File
@@ -772,7 +772,9 @@ router.get('/miniapp/article/:category', require('./routes/miniapp/article'));
router.get('/miniapp/store/newest', require('./routes/miniapp/store/newest'));
// 后续
router.get('/houxu/:type/:id', require('./routes/houxu/houxu'));
router.get('/houxu/live/:id/:timeline?', require('./routes/houxu/live'));
router.get('/houxu/events', require('./routes/houxu/events'));
router.get('/houxu/lives/:type', require('./routes/houxu/lives'));
// 老司机
router.get('/laosiji/hot', require('./routes/laosiji/hot'));
+50
View File
@@ -0,0 +1,50 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const baseUrl = `https://houxu.app/events`;
const res = await axios.get(baseUrl);
const data = res.data;
const $ = cheerio.load(data);
const list = $('div.list > div');
const descriptionSelector = '.summary';
const out = list
.map((_, el) => {
const each = $(el);
return {
title:
each
.find('a')
.first()
.text()
.trim() +
' | ' +
each
.find('h3')
.text()
.trim(),
description: each
.find(descriptionSelector)
.text()
.trim(),
link:
'https://houxu.app' +
each
.find('a')
.first()
.attr('href'),
};
})
.get();
ctx.state.data = {
title: $('title')
.text()
.trim(),
description: $('title')
.text()
.trim(),
link: baseUrl,
item: out,
};
};
-35
View File
@@ -1,35 +0,0 @@
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,
};
};
+47
View File
@@ -0,0 +1,47 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { id, timeline } = ctx.params;
const filter = timeline ? timeline : 'all';
const baseUrl = `https://houxu.app/lives/${id}?filter=${filter}`;
const res = await axios.get(baseUrl);
const data = res.data;
const $ = cheerio.load(data);
const list = $('section.threads > div');
const out = list
.map((_, el) => {
const each = $(el);
return {
title:
each
.find('a')
.first()
.text()
.trim() +
' | ' +
each
.find('h3')
.text()
.trim(),
description: each
.find('.summary')
.text()
.trim(),
link: each
.find('a')
.first()
.attr('href'),
};
})
.get();
ctx.state.data = {
title: $('.large-title').text(),
description: $('title')
.text()
.trim(),
link: baseUrl,
item: out,
};
};
+54
View File
@@ -0,0 +1,54 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { type } = ctx.params;
const baseUrl = `https://houxu.app/lives/${type}`;
const res = await axios.get(baseUrl);
const data = res.data;
const $ = cheerio.load(data);
const list = $('div.list > div');
const out = list
.map((_, el) => {
const each = $(el);
return {
title:
each
.find('cite')
.text()
.trim() +
' | ' +
each
.find('a')
.first()
.text()
.trim(),
description: each
.find('p > a')
.contents()
.filter(function() {
return this.nodeType === 3;
})
.text()
.trim(),
link:
'https://houxu.app' +
each
.find('a')
.first()
.attr('href'),
};
})
.get();
ctx.state.data = {
title: $('title')
.text()
.trim(),
description: $('li.active')
.text()
.trim(),
link: baseUrl,
item: out,
};
};