mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-01 17:48:15 +08:00
* 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>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
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,
|
|
};
|
|
};
|