mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-12 08:10:32 +08:00
* Add(route): add Google Fonts and change to V2 * Fix(route): added throw error when API key is underfined * Fix(docs): add warning container * Fix(docs): Update docs/design.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Fix(route): sort routes * Fix(route): Update lib/v2/google/fonts.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
|
|
module.exports = async (ctx) => {
|
|
let params = ctx.params.query;
|
|
let query = params;
|
|
let description = `Google Scholar Monitor Query: ${query}`;
|
|
|
|
if (params.indexOf('as_q=', 0) !== -1) {
|
|
const reg = /as_q=(.*?)&/g;
|
|
query = reg.exec(params)[1];
|
|
description = `Google Scholar Monitor Advanced Query: ${query}`;
|
|
} else {
|
|
params = 'q=' + params;
|
|
}
|
|
|
|
const url = `https://scholar.google.com/scholar?${params}`;
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url,
|
|
});
|
|
|
|
const $ = cheerio.load(response.data);
|
|
const list = $('#gs_res_ccl_mid .gs_r.gs_or.gs_scl .gs_ri').get();
|
|
|
|
const out = list.map((item) => {
|
|
const $ = cheerio.load(item);
|
|
const itemUrl = $('h3 a').attr('href');
|
|
return {
|
|
title: $('h3 a').text(),
|
|
author: $('.gs_a').text(),
|
|
description: $('.gs_rs').text(),
|
|
link: itemUrl,
|
|
guid: itemUrl,
|
|
};
|
|
});
|
|
|
|
ctx.state.data = {
|
|
title: `Google Scholar Monitor: ${query}`,
|
|
link: url,
|
|
description,
|
|
item: out,
|
|
};
|
|
};
|