From 488a166246ac7a8f2eb55b792aa96d5b99d056ef Mon Sep 17 00:00:00 2001 From: zengxs Date: Tue, 30 Apr 2019 00:18:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20Saraba1st=20?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E8=AE=A2=E9=98=85=20(#2011)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/social-media.md | 8 ++++++ lib/router.js | 3 +++ lib/routes/saraba1st/thread.js | 47 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/routes/saraba1st/thread.js diff --git a/docs/social-media.md b/docs/social-media.md index 76063020cb..87363771ed 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -450,6 +450,14 @@ +# Saraba1st + + + +帖子网址如果为 那么帖子 id 就是 `1789863`。 + + + ## Facebook diff --git a/lib/router.js b/lib/router.js index 1e61702e04..811774e285 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1293,4 +1293,7 @@ router.get('/ps/list/:gridName', require('./routes/ps/list')); // 毕马威 router.get('/kpmg/insights', require('./routes/kpmg/insights')); +// Saraba1st +router.get('/saraba1st/thread/:tid', require('./routes/saraba1st/thread')); + module.exports = router; diff --git a/lib/routes/saraba1st/thread.js b/lib/routes/saraba1st/thread.js new file mode 100644 index 0000000000..842f96cbc7 --- /dev/null +++ b/lib/routes/saraba1st/thread.js @@ -0,0 +1,47 @@ +const url = require('url'); +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const date = require('../../utils/date'); + +module.exports = async (ctx) => { + const tid = ctx.params.tid; + + const res = await axios.get('https://bbs.saraba1st.com/2b/forum.php', { + params: { + mod: 'viewthread', + tid: tid, + ordertype: 1, + }, + }); + + const $ = cheerio.load(res.data); + const title = $('#thread_subject').text(); + + const list = $('#postlist > div[id^=post_]:not(:first-of-type)'); + const count = []; + + for (let i = 0; i < Math.min(list.length, 10); i++) { + count.push(i); + } + const resultItems = await Promise.all( + count.map(async (i) => { + const each = $(list[i]); + const floor = each.find('td.plc .pi a > em').text(); + const floorUrl = each.find('td.plc .pi a').attr('href'); + const item = { + title: `${title} #${floor}`, + link: url.resolve('https://bbs.saraba1st.com/2b/', floorUrl), + description: each.find('td.t_f').html(), + author: each.find('.authi .xw1').text(), + pubDate: date(each.find('.authi em').text()), + }; + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: `Stage1 论坛 - ${title}`, + link: `https://bbs.saraba1st.com/2b/thread-${tid}-1-1.html`, + item: resultItems, + }; +};