Add Gitlab Explore close #507 (#525)

This commit is contained in:
imlonghao 2018-08-24 15:17:19 +08:00 committed by DIYgod
parent 60ec492874
commit 2bf781d389
4 changed files with 57 additions and 0 deletions

View File

@ -254,6 +254,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- 笔趣阁
- UU 看书
- 文学迷
- Gitlab
- Explore
</details>

View File

@ -2077,3 +2077,19 @@ type必选目前支持两种`hot` 代表热门游记,`latest` 代表
参数: id1/id2小说网站链接最后的数字可在对应小说页 URL 中找到
举例网址https://www.wenxuemi.com/files/article/html/6/6144/
## Gitlab
### Explore <Author uid="imlonghao"/>
举例: [https://rsshub.app/gitlab/explore/trending](https://rsshub.app/gitlab/explore/trending)
路由: `/gitlab/explore/:type`
参数:
type分类
| Trending | Most stars | All |
| -------- | ---------- | --- |
| trending | starred | all |

View File

@ -454,4 +454,7 @@ router.get('/novel/biquge/:id', require('./routes/novel/biquge'));
router.get('/novel/uukanshu/:uid', require('./routes/novel/uukanshu'));
router.get('/novel/wenxuemi/:id1/:id2', require('./routes/novel/wenxuemi'));
// Gitlab
router.get('/gitlab/explore/:type', require('./routes/gitlab/explore'));
module.exports = router;

36
routes/gitlab/explore.js Normal file
View File

@ -0,0 +1,36 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const type = ctx.params.type === 'all' ? '' : ctx.params.type;
const typename = {
trending: 'Trending',
starred: 'Most stars',
all: 'All',
};
const res = await axios({
method: 'get',
url: `https://gitlab.com/explore/projects/${type}`,
});
const data = res.data;
const $ = cheerio.load(data);
const list = $('ul.projects-list').find('li');
ctx.state.data = {
title: `${typename[ctx.params.type]} - Explore - Gitlab`,
link: `https://gitlab.com/explore/projects/${type}`,
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('.project-full-name').text(),
description: item.find('.description').text(),
link: `https://gitlab.com${item.find('a.text-plain').attr('href')}`,
};
})
.get(),
};
};