feat: add processon popular (#6240)

This commit is contained in:
Ethan Shen 2020-11-30 03:14:46 +08:00 committed by GitHub
parent f02a8515f3
commit c3cfd17962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 0 deletions

View File

@ -127,6 +127,26 @@ pageClass: routes
| wsk | 全国外语水平考试 (WSK) |
| mets | 医护英语水平考试 (METS) |
## ProcessOn
### 推荐
<Route author="nczitzk" example="/processon/popular" path="/processon/popular/:cate?/:sort?" :paramsDesc="['分类,见下表,默认为所有类型', '排序,见下表,默认为人气']">
分类
| 所有类型 | 流程图 | BPMN | 思维导图 | UI 原型图 | UML | Org 组织结构图 | 网络拓扑图 | 韦恩图 | |
| -------- | ------ | ---- | -------- | --------- | --- | -------------- | ---------- | ------- | ---- |
| | es | flow | bpmn | mind_free | ui | uml | org | network | venn |
排序
| 人气 | 最多人赞 | 最多收藏 | 最多浏览 | 最新发布 |
| ---- | --------- | -------------- | --------- | ----------- |
| | likeCount | favouriteCount | viewCount | publishTime |
</Route>
## X-MOL 平台
### 新闻

View File

@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// ProcessOn
router.get('/processon/popular/:cate?/:sort?', require('./routes/processon/popular'));
// Mathpix
router.get('/mathpix/blog', require('./routes/mathpix/blog'));

View File

@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const cate = ctx.params.cate || '';
const sort = ctx.params.sort || '';
const rootUrl = 'https://www.processon.com';
const currentUrl = `${rootUrl}/popular/?cate=${cate}&sort=${sort}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('a.chart-title')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
link: `${rootUrl}${item.attr('href')}`,
description: `${item.parent().prev().html()}<p>${item.parent().find('p').text()}</p>`,
};
})
.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.author = content('a.user_quickinfo').text();
item.pubDate = content('.chart-pubtime').text().split('发布于 ')[1];
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};