diff --git a/docs/programming.md b/docs/programming.md index 87f5549428..a160cabf25 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -30,6 +30,16 @@ pageClass: routes +## dbaplus 社群 + + + +| 全部 | 数据库 | 运维 | 大数据 | 架构 | PaaS 云 | 职场生涯 | 这里有毒 | +| ---- | ------ | ---- | ------ | ---- | ------- | -------- | -------- | +| All | 153 | 134 | 73 | 141 | 72 | 149 | 21 | + + + ## deeplearning.ai ### TheBatch 周报 diff --git a/lib/router.js b/lib/router.js index 21403d7e19..0fbf1925c9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4042,6 +4042,9 @@ router.get('/wainao-reads/all-articles', require('./routes/wainao/index')); // react router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly')); +// dbaplus 社群 +router.get('/dbaplus/:tab?', require('./routes/dbaplus/tab')); + // 梨园 router.get('/liyuan-forums/threads', require('./routes/liyuan-forums/threads')); router.get('/liyuan-forums/threads/forum/:forum_id', require('./routes/liyuan-forums/threads')); diff --git a/lib/routes/dbaplus/tab.js b/lib/routes/dbaplus/tab.js new file mode 100644 index 0000000000..ffe0be351f --- /dev/null +++ b/lib/routes/dbaplus/tab.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const tab = ctx.params.tab || 'All'; + + const rootUrl = 'https://dbaplus.cn'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $(`#tab${tab} li`) + .slice(0, 15) + .map((_, item) => { + item = $(item); + + return { + link: item.find('a').eq(0).attr('href'), + }; + }) + .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.title = content('h2.title').text(); + item.author = content('span.user').text(); + item.description = content('.new-detailed').html(); + item.pubDate = new Date(content('span.time').eq(0).text()).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${response.data.match(`(.*)`)[1]} - dbaplus社群`, + link: rootUrl, + item: items, + }; +};