mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 07:12:51 +08:00
@@ -668,6 +668,15 @@ GitHub 官方也提供了一些 RSS:
|
|||||||
|
|
||||||
<route name="仓库 Stars" author="HenryQW" example="/github/stars/DIYgod/RSSHub" path="/github/stars/:user/:repo" :paramsDesc="['用户名', '仓库名']"/>
|
<route name="仓库 Stars" author="HenryQW" example="/github/stars/DIYgod/RSSHub" path="/github/stars/:user/:repo" :paramsDesc="['用户名', '仓库名']"/>
|
||||||
|
|
||||||
|
<route name="搜索结果" author="LogicJake" example="/github/search/RSSHub/bestmatch/desc" path="/github/search/:query/:sort?/:order?" :paramsDesc="['搜索关键词', '排序选项(默认为bestmatch)','排序顺序,desc和asc(默认desc降序)']"/>
|
||||||
|
|
||||||
|
| 排序选项 | sort |
|
||||||
|
| ------------------ | --------- |
|
||||||
|
| 最佳匹配 | bestmatch |
|
||||||
|
| 根据 star 数量排序 | stars |
|
||||||
|
| 根据 fork 数量排序 | forks |
|
||||||
|
| 根据更新时间排序 | updated |
|
||||||
|
|
||||||
### 开源中国
|
### 开源中国
|
||||||
|
|
||||||
<route name="资讯" author="tgly307" example="/oschina/news" path="/oschina/news"/>
|
<route name="资讯" author="tgly307" example="/oschina/news" path="/oschina/news"/>
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ router.get('/github/trending/:since/:language?', require('./routes/github/trendi
|
|||||||
router.get('/github/issue/:user/:repo', require('./routes/github/issue'));
|
router.get('/github/issue/:user/:repo', require('./routes/github/issue'));
|
||||||
router.get('/github/user/followers/:user', require('./routes/github/follower'));
|
router.get('/github/user/followers/:user', require('./routes/github/follower'));
|
||||||
router.get('/github/stars/:user/:repo', require('./routes/github/star'));
|
router.get('/github/stars/:user/:repo', require('./routes/github/star'));
|
||||||
|
router.get('/github/search/:query/:sort?/:order?', require('./routes/github/search'));
|
||||||
|
|
||||||
// f-droid
|
// f-droid
|
||||||
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
|
router.get('/fdroid/apprelease/:app', require('./routes/fdroid/apprelease'));
|
||||||
|
|||||||
47
lib/routes/github/search.js
Normal file
47
lib/routes/github/search.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
const axios = require('../../utils/axios');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
const host = 'https://github.com';
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const query = ctx.params.query;
|
||||||
|
let sort = ctx.params.sort || 'bestmatch';
|
||||||
|
const order = ctx.params.order || 'desc';
|
||||||
|
|
||||||
|
if (sort === 'bestmatch') {
|
||||||
|
sort = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = 'search?o='.concat(order, '&q=', query, '&s=', sort, '&type=Repositories');
|
||||||
|
const link = url.resolve(host, suffix);
|
||||||
|
const response = await axios.get(link);
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
|
||||||
|
const out = $('.repo-list li')
|
||||||
|
.slice(0, 10)
|
||||||
|
.map(function() {
|
||||||
|
const single = {
|
||||||
|
title: $(this)
|
||||||
|
.find('div h3 a')
|
||||||
|
.text(),
|
||||||
|
link: host.concat(
|
||||||
|
$(this)
|
||||||
|
.find('div h3 a')
|
||||||
|
.attr('href')
|
||||||
|
),
|
||||||
|
description: $(this)
|
||||||
|
.find('div p')
|
||||||
|
.text()
|
||||||
|
.trim(),
|
||||||
|
};
|
||||||
|
return single;
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `${query}的搜索结果`,
|
||||||
|
link: link,
|
||||||
|
item: out,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user