From 566096ff4056281aa5b828f87866d2e707baaade Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 7 Jul 2020 17:29:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=9B=B4=E6=92=AD=E5=90=A7?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=96=B0=E9=97=BB=20(#5133)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bbs.md | 4 ++++ lib/router.js | 1 + lib/routes/zhibo8/more.js | 46 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 lib/routes/zhibo8/more.js diff --git a/docs/bbs.md b/docs/bbs.md index 914771366..fa0deaa51 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -385,3 +385,7 @@ pageClass: routes ### 回帖 + +### 滚动新闻 + + diff --git a/lib/router.js b/lib/router.js index a5f0f09ae..a6d139fc1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/zhibo8/more.js b/lib/routes/zhibo8/more.js new file mode 100644 index 000000000..57f0fea86 --- /dev/null +++ b/lib/routes/zhibo8/more.js @@ -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, + }; +};