From fda0b82a885aea0a9a3bfe0dbb64daec9eff3ee4 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Wed, 12 Jun 2019 11:12:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=9B=B4=E6=92=AD=E5=90=A7=20(#2?= =?UTF-8?q?379)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/social-media.md | 10 +++++++ lib/router.js | 4 +++ lib/routes/zhibo8/forum.js | 55 ++++++++++++++++++++++++++++++++++++++ lib/routes/zhibo8/post.js | 42 +++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 lib/routes/zhibo8/forum.js create mode 100644 lib/routes/zhibo8/post.js diff --git a/docs/social-media.md b/docs/social-media.md index b30d20a37..20efcc942 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -720,6 +720,16 @@ pageClass: routes +## 直播吧 + +### 子论坛 + + + +### 回帖 + + + ## 知乎 ### 收藏夹 diff --git a/lib/router.js b/lib/router.js index d756edde1..1748cd284 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1397,6 +1397,10 @@ router.get('/005tv/zx/latest', require('./routes/005tv/zx')); // Polimi News router.get('/polimi/news/:language?', require('./routes/polimi/news')); +// 直播吧 +router.get('/zhibo8/forum/:id', require('./routes/zhibo8/forum')); +router.get('/zhibo8/post/:id', require('./routes/zhibo8/post')); + // 东方网-上海 router.get('/eastday/sh', require('./routes/eastday/sh')); diff --git a/lib/routes/zhibo8/forum.js b/lib/routes/zhibo8/forum.js new file mode 100644 index 000000000..c03b02d7e --- /dev/null +++ b/lib/routes/zhibo8/forum.js @@ -0,0 +1,55 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `https://bbs.zhibo8.cc/forum/list/?fid=${id}`; + + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const title = $('div.intro > h2').text(); + const list = $('table.topic-list > tbody:nth-child(3) > tr'); + + const out = await Promise.all( + list + .map(async (index, item) => { + item = $(item); + const title = item.find('td:nth-child(1) > a:nth-child(2)').text(); + const author = item.find('td:nth-child(2) cite a').text(); + const date = item.find('td:nth-child(2) em').text(); + const link = 'https://bbs.zhibo8.cc' + item.find('td:nth-child(1) > a:nth-child(2)').attr('href'); + + const single = { + title, + author, + link, + pubDate: new Date(date).toUTCString(), + }; + + const key = link; + const value = await ctx.cache.get(key); + if (value) { + single.description = value; + } else { + const response = await got.get(link); + const $ = cheerio.load(response.data); + $('.detail_ent img').each(function() { + const $img = $(this); + const src = $img.attr('src'); + $img.attr('src', 'https:' + src); + }); + single.description = $('.detail_ent').html(); + ctx.cache.set(key, single.description, 12 * 60 * 60); + } + return Promise.resolve(single); + }) + .get() + ); + + ctx.state.data = { + title: `${title}—直播吧`, + link: link, + item: out, + }; +}; diff --git a/lib/routes/zhibo8/post.js b/lib/routes/zhibo8/post.js new file mode 100644 index 000000000..8171aa4aa --- /dev/null +++ b/lib/routes/zhibo8/post.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `https://bbs.zhibo8.cc/forum/topic?tid=${id}`; + + const response = await got.get(link); + const $ = cheerio.load(response.data); + + const title = $('div.topic-title > h1').text(); + const list = $('.topic-content .topic-table'); + + const out = await Promise.all( + list + .map(async (index, item) => { + item = $(item); + const author = item.find('.topic-left > div > a').text(); + const floor = item.find('p.topic-foot span:nth-child(2)').text(); + const description = item + .find('.detail_ent') + .html() + .replace(/src="/g, 'src="https:'); + + const single = { + title: `${floor}:${author}发表了新回复`, + author, + description, + guid: floor, + }; + + return Promise.resolve(single); + }) + .get() + ); + + ctx.state.data = { + title: `“${title}”的新回复—直播吧`, + link: link, + item: out, + }; +};