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, + }; +};