modify: houxu/lives (#1883)
fix: houxu/lives/new 为空的问题 refactor: houxu/lives 从后续 App 接口获取数据,增加摘要显示 docs: 调整 houxu/lives 的文档,描述更加清晰
This commit is contained in:
parent
ee8801ba6c
commit
22970a2d42
|
|
@ -183,7 +183,13 @@
|
|||
|
||||
</Route>
|
||||
|
||||
<Route name="最新Live" author="ciaranchen" example="/houxu/lives/new" path="/houxu/lives/:type" :paramsDesc="['类型。实时进展`realtime` 或 最近关注`new`']" />
|
||||
<Route name="最新Live" author="ciaranchen" example="/houxu/lives/new" path="/houxu/lives/:type" :paramsDesc="['类型']">
|
||||
|
||||
| Live 实时(往事进展) | 最近 Live(最新关注) |
|
||||
| --------------------- | --------------------- |
|
||||
| realtime | new |
|
||||
|
||||
</Route>
|
||||
|
||||
<Route name="最新专栏" author="ciaranchen" example="/houxu/events" path="/houxu/events"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,34 +1,56 @@
|
|||
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 $ = cheerio.load(res.data);
|
||||
const liveUrlById = (liveId) => `https://houxu.app/lives/${liveId}`;
|
||||
|
||||
const list = $('div.live-realtime');
|
||||
const out = list
|
||||
.map((_, el) => {
|
||||
const each = $(el);
|
||||
const realtimeHandler = async () => {
|
||||
const res = await axios.get('https://houxu.app/api/1/lives/updated/');
|
||||
const out = res.data.results.map((el) => ({
|
||||
title: el.last.link.title,
|
||||
description: el.last.link.media.name + ':<br />' + el.last.link.description,
|
||||
link: liveUrlById(el.id),
|
||||
guid: 'realtime-' + el.id + '-' + el.last.id,
|
||||
pubDate: new Date(el.last.create_at).toUTCString(),
|
||||
}));
|
||||
|
||||
return {
|
||||
title: each
|
||||
.find('h4 > a')
|
||||
.text()
|
||||
.trim(),
|
||||
link: 'https://houxu.app' + each.find('h4 > a').attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
ctx.state.data = {
|
||||
title: $('title')
|
||||
.text()
|
||||
.trim(),
|
||||
description: $('li.active')
|
||||
.text()
|
||||
.trim(),
|
||||
link: baseUrl,
|
||||
return {
|
||||
title: 'Live 实时 - 后续',
|
||||
description: 'Live 往事进展',
|
||||
link: 'https://houxu.app/lives/realtime',
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
||||
const newHandler = async () => {
|
||||
const res = await axios.get('https://houxu.app/api/1/records/index/');
|
||||
const out = res.data.results
|
||||
.filter((el) => el.type === 'live')
|
||||
.map((el) => ({
|
||||
title: el.object.title,
|
||||
description: el.object.summary,
|
||||
link: liveUrlById(el.id),
|
||||
guid: 'new-' + el.id + '-' + el.object.id,
|
||||
pubDate: new Date(el.object.create_at).toUTCString(),
|
||||
}));
|
||||
return {
|
||||
title: '最近 Live - 后续',
|
||||
description: 'Live 最新关注',
|
||||
link: 'https://houxu.app/lives/new',
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { type } = ctx.params;
|
||||
|
||||
switch (type) {
|
||||
case 'realtime':
|
||||
ctx.state.data = await realtimeHandler();
|
||||
break;
|
||||
case 'new':
|
||||
ctx.state.data = await newHandler();
|
||||
break;
|
||||
default:
|
||||
ctx.throw(404, 'Unknown lives type');
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue