mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 10:08:02 +08:00
fix(route): fix GitHub route parameter conflict at trending.js and refactor to V2 (#8923)
* Fix(route): fix route parameter conflict at trending.js and change to V2 * Fix(route): modify the judgment condition of language parameter * Fix(docs): Update docs/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Fix(docs): Update docs/en/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix(docs/route): add author and sort routes * Fix(route): Update docs/en/programming.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Fix(route): sort routes Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
41
lib/v2/github/search.js
Normal file
41
lib/v2/github/search.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const got = require('@/utils/got');
|
||||
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=', encodeURIComponent(query), '&s=', sort, '&type=Repositories');
|
||||
const link = url.resolve(host, suffix);
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const out = $('.repo-list li')
|
||||
.slice(0, 10)
|
||||
.map(function () {
|
||||
const a = $(this).find('.f4.text-normal > a');
|
||||
const single = {
|
||||
title: a.text(),
|
||||
author: a.text().split('/')[0].trim(),
|
||||
link: host.concat(a.attr('href')),
|
||||
description: $(this).find('div p').text().trim(),
|
||||
};
|
||||
return single;
|
||||
})
|
||||
.get();
|
||||
|
||||
ctx.state.data = {
|
||||
allowEmpty: true,
|
||||
title: `${query}的搜索结果`,
|
||||
link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user