diff --git a/docs/programming.md b/docs/programming.md index 25bd7f29b1..13860cd266 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -342,6 +342,10 @@ GitHub 官方也提供了一些 RSS: | 备案公告 | 3 | | 其他 | 4 | +### 开发者社区-主题 + + + ## 安全客 ::: tip 提示 diff --git a/lib/router.js b/lib/router.js index ac6e421965..77a3e6325c 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1831,6 +1831,7 @@ router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ // 阿里云 router.get('/aliyun/database_month', require('./routes/aliyun/database_month')); router.get('/aliyun/notice/:type?', require('./routes/aliyun/notice')); +router.get('/aliyun/developer/group/:type', require('./routes/aliyun/developer/group')); // 礼物说 router.get('/liwushuo/index', require('./routes/liwushuo/index.js')); diff --git a/lib/routes/aliyun/developer/group.js b/lib/routes/aliyun/developer/group.js new file mode 100644 index 0000000000..235824be2b --- /dev/null +++ b/lib/routes/aliyun/developer/group.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const type = ctx.params.type; + const link = `https://developer.aliyun.com/group/${type}`; + + // 发起 HTTP GET 请求 + const response = await got({ + method: 'get', + url: link, + }); + + const data = response.data; + + // 使用 cheerio 加载返回的 HTML + const $ = cheerio.load(data); + const title = $('div[class="header-information-title"]') + .contents() + .filter(function () { + return this.nodeType === 3; + }) + .text() + .trim(); + const desc = $('div[class="header-information"]').find('span').last().text().trim(); + const list = $('ul[class^="content-tab-list"] > li'); + + ctx.state.data = { + title: `阿里云开发者社区-${title}`, + link, + description: `${desc}`, + item: + list && + list + .map((index, item) => { + item = $(item); + return { + title: item.find('p').first().text().trim(), + link: item.find('a').attr('href'), + }; + }) + .get(), + }; +};