feat: add route for aliyun developer topic (#4584)

This commit is contained in:
umm233
2020-04-28 11:55:43 +08:00
committed by GitHub
parent 13757932af
commit 5e3ccee8c7
3 changed files with 49 additions and 0 deletions

View File

@@ -342,6 +342,10 @@ GitHub 官方也提供了一些 RSS:
| 备案公告 | 3 |
| 其他 | 4 |
### 开发者社区-主题
<Route author="umm233" example="/aliyun/developer/group/alitech" path="/aliyun/developer/group/:type" :paramsDesc="['对应技术领域分类']" />
## 安全客
::: tip 提示

View File

@@ -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'));

View File

@@ -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(),
};
};