feat: implement github topics router (#5803) (#6792)

This commit is contained in:
Queensferry
2021-01-26 00:08:43 -05:00
committed by GitHub
parent 8ebbd0d708
commit 79a3d36c2b
5 changed files with 60 additions and 0 deletions
+6
View File
@@ -248,6 +248,12 @@
source: '/trending',
target: '/github/trending/:since',
},
{
title: 'Trending',
docs: 'https://docs.rsshub.app/programming.html#github',
source: '/topics',
target: '/github/topics/:name/:qs?',
},
{
title: '仓库 Issue',
docs: 'https://docs.rsshub.app/programming.html#github',
+14
View File
@@ -37,6 +37,20 @@ GitHub provides some official RSS feeds:
<RouteEn path="/github/trending/:since/:language?" example="/github/trending/daily/javascript" :paramsDesc="['time frame, available in [Trending page](https://github.com/trending/javascript?since=monthly) \'s URL, possible values are: daily, weekly or monthly', 'the feed language, available in [Trending page](https://github.com/trending/javascript?since=monthly) \'s URL']" radar="1" rssbud="1"/>
### Topics
<Route author="queensferryme" example="/github/topics/framework" path="/github/topics/:name/:qs?" :paramsDesc="['Topic name, which can be found in the URL of the corresponding [Topics Page](https://github.com/topics/framework)', 'Query string, like `l=php&o=desc&s=stars`. Details listed as follows:']" radar="1" rssbud="1">
| Parameter | Description | Values |
| ---- | ---- | ---- |
| `l` | Language | For instance `php`, which can be found in the URL of the corresponding [Topics page](https://github.com/topics/framework?l=php) |
| `o` | Sorting Order | `asc`, `desc` |
| `s` | Sorting Criteria | `stars`, `forks`, `updated` |
For instance, the `/github/topics/framework/l=php&o=desc&s=stars` route will generate the RSS feed corresponding to this [page](https://github.com/topics/framework?l=php&o=desc&s=stars).
</Route>
### Repo Issues
<RouteEn author="HenryQW AndreyMZ" path="/github/issue/:user/:repo/:state?/:labels?" example="/github/issue/DIYgod/RSSHub/all/bug" :paramsDesc="['GitHub username', 'GitHub repo name', 'the state of the issues. Can be either `open`, `closed`, or `all`. Default: `open`.', 'a list of comma separated label names']" radar="1" rssbud="1"/>
+14
View File
@@ -93,6 +93,20 @@ GitHub 官方也提供了一些 RSS:
<Route author="DIYgod" example="/github/trending/daily/javascript" path="/github/trending/:since/:language?" :paramsDesc="['时间跨度, 可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到, 可选 daily weekly monthly', '语言, 可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到']" radar="1" rssbud="1"/>
### Topics
<Route author="queensferryme" example="/github/topics/framework" path="/github/topics/:name/:qs?" :paramsDesc="['名称,可以在相关 [Topics 页](https://github.com/topics/framework) URL 中找到', '过滤规则,形如 `l=php&o=desc&s=stars`,详见下表']" radar="1" rssbud="1">
| 参数名 | 描述 | 可选值 |
| ------ | -------- | ----------------------------------------------------------------------------------------- |
| `l` | 编程语言 | 例如 `php`,可以在相关 [Topics 页](https://github.com/topics/framework?l=php) URL 中找到 |
| `o` | 排序方法 | `asc`(升序)<br>`desc`(降序) |
| `s` | 排序标准 | `stars`(按 star 数量排序)<br>`forks`(按 fork 数量排序)<br>`updated`(按更新日期排序) |
例如 `/github/topics/framework/l=php&o=desc&s=stars` 会生成对应[此页面](https://github.com/topics/framework?l=php&o=desc&s=stars)的 RSS。
</Route>
### 仓库 Issues
<Route author="HenryQW AndreyMZ" example="/github/issue/DIYgod/RSSHub/open/RSS%20wanted" path="/github/issue/:user/:repo/:state?/:labels?" :paramsDesc="['用户名', '仓库名', 'issue 状态,可选`open`,`closed`或`all`,默认为`open`', '标签列表,以逗号分隔']" radar="1" rssbud="1"/>
+1
View File
@@ -307,6 +307,7 @@ router.get('/github/branches/:user/:repo', require('./routes/github/branches'));
router.get('/github/file/:user/:repo/:branch/:filepath+', require('./routes/github/file'));
router.get('/github/starred_repos/:user', require('./routes/github/starred_repos'));
router.get('/github/contributors/:user/:repo/:order?/:anon?', require('./routes/github/contributors'));
router.get('/github/topics/:name/:qs?', require('./routes/github/topic'));
// f-droid
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
+25
View File
@@ -0,0 +1,25 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const link = `https://github.com/topics/${ctx.params.name}?${ctx.params.qs}`;
const { data } = await got(link);
const $ = cheerio.load(data);
ctx.state.data = {
title: $('title').text(),
link,
item: $('article.my-4')
.map((_, item) => {
item = $(item);
const title = $(item.find('h1 a').get(1)).attr('href').slice(1);
const author = title.split('/')[0];
const description = `${item.find('div.border-bottom > div > p + div').text()}`;
const link = `https://github.com/${title}`;
return { title, author, description, link };
})
.get(),
};
};