feat: add 直播吧滚动新闻 (#5133)

This commit is contained in:
Ethan Shen
2020-07-07 17:29:02 +08:00
committed by GitHub
parent ef3ed0e5c1
commit 566096ff40
3 changed files with 51 additions and 0 deletions
+4
View File
@@ -385,3 +385,7 @@ pageClass: routes
### 回帖
<Route author="LogicJake" example="/zhibo8/post/2601615" path="/zhibo8/post/:id" :paramsDesc="['帖子 id,可在帖子 URL 找到']"/>
### 滚动新闻
<Route author="nczitzk" example="/zhibo8/more/nba" path="/zhibo8/more/:caty" :paramsDesc="['分类,可选 `nba` 指 NBA,或 `zuqiu` 指 足球']"/>
+1
View File
@@ -1695,6 +1695,7 @@ router.get('/dekudeals/:type', require('./routes/dekudeals'));
// 直播吧
router.get('/zhibo8/forum/:id', require('./routes/zhibo8/forum'));
router.get('/zhibo8/post/:id', require('./routes/zhibo8/post'));
router.get('/zhibo8/more/:caty', require('./routes/zhibo8/more'));
// 东方网-上海
router.get('/eastday/sh', require('./routes/eastday/sh'));
+46
View File
@@ -0,0 +1,46 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const currentUrl = `https://news.zhibo8.cc/${ctx.params.caty}/more.htm`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('ul.articleList li')
.slice(0, 30)
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: `http:${a.attr('href')}`,
pubDate: new Date(item.find('span.postTime').text() + ' GMT+8').toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const res = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(res.data);
item.description = content('div.content').html();
return item;
})
)
);
ctx.state.data = {
title: `${$('span.title_g').text()} - 直播吧`,
link: currentUrl,
item: items,
};
};