diff --git a/docs/bbs.md b/docs/bbs.md index 8487bb0ad..9458bd32c 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -184,6 +184,10 @@ pageClass: routes +### 驿站帖子 + + + ## 电鸭社区 ### 工作机会 diff --git a/lib/router.js b/lib/router.js index 3ed31da3d..7c654d71b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2966,6 +2966,7 @@ router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj')); // 才符 router.get('/91ddcc/user/:user', require('./routes/91ddcc/user')); +router.get('/91ddcc/stage/:stage', require('./routes/91ddcc/stage')); // BookwalkerTW热门新书 router.get('/bookwalkertw/news', require('./routes/bookwalkertw/news')); diff --git a/lib/routes/91ddcc/stage.js b/lib/routes/91ddcc/stage.js new file mode 100644 index 000000000..4048da92b --- /dev/null +++ b/lib/routes/91ddcc/stage.js @@ -0,0 +1,49 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = `https://sns.91ddcc.com/s/${ctx.params.stage}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + const list = $('div.log-box div.l-single') + .slice(0, 5) + .map((_, item) => { + item = $(item); + const a = item.find('div.word a.s-til'); + return { + title: a.text(), + link: `https://sns.91ddcc.com${a.attr('href')}`, + pubDate: new Date(item.find('div.floor a.fr').text() + ' GMT+8').toUTCString(), + author: item.find('div.floor a.fl').text(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('div.article-con').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('a.name').text()} - 才符`, + link: currentUrl, + item: items, + description: $('div.bot-info').text(), + }; +};