fix(route): link research (#11051)

This commit is contained in:
Tony 2022-10-11 03:37:58 +11:00 committed by GitHub
parent 3ceaa21bb6
commit 8b97dce251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 19 deletions

View File

@ -35,15 +35,15 @@ pageClass: routes
</RouteEn>
## LinkResearch
## Link Research
### theses
### Theses
<RouteEn author="yech1990" example="/linkresearcher/category=theses&subject=生物" path="/linkresearcher/theses/:param" supportScihub="1" :paramsDesc="['key=valueeg. subject=生物']">
<RouteEn author="yech1990" example="/linkresearcher/category=theses&subject=生物" path="/linkresearcher/theses/:param" supportScihub="1" :paramsDesc="['key=valueeg. subject=生物']" radar="1" rssbud="1">
| `:param` | example | definition |
| -------- | --------------- | -------------------------------------- |
| category | category=thesis | **one of**theses/information/careers |
| category | category=thesis | **one of** theses/information/careers |
| subject | subject=生物 | string / undefined |
| columns | columns=健康 | string / undefined |
| columns | columns=virus | string / undefined |

View File

@ -317,7 +317,7 @@ path="/ctfhub/upcoming/:limit?"
### 论文
<Route author="yech1990" example="/linkresearcher/category=theses&subject=生物" path="/linkresearcher/theses/:param" supportScihub="1" :paramsDesc="['参数,如 subject=生物']"/>
<Route author="yech1990" example="/linkresearcher/category=theses&subject=生物" path="/linkresearcher/theses/:param" supportScihub="1" :paramsDesc="['参数,如 subject=生物']" radar="1" rssbud="1">
| `:param` | 举例 | 定义 |
| -------- | --------------- | --------------------------------- |
@ -326,6 +326,8 @@ path="/ctfhub/upcoming/:limit?"
| columns | columns = 健康 | 可置空 |
| query | query = 病毒 | 可置空 |
</Route>
## 码农周刊
### issues

View File

@ -2160,7 +2160,7 @@ router.get('/kaggle/user/:user', lazyloadRouteHandler('./routes/kaggle/user'));
// router.get('/pubmed/trending', lazyloadRouteHandler('./routes/pubmed/trending'));
// 领科 (linkresearcher.com)
router.get('/linkresearcher/:params', lazyloadRouteHandler('./routes/linkresearcher/index'));
// router.get('/linkresearcher/:params', lazyloadRouteHandler('./routes/linkresearcher/index'));
// eLife [Sci Journal]
router.get('/elife/:tid', lazyloadRouteHandler('./routes/elife/index'));

View File

@ -1,6 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const qs = require('querystring');
const qs = require('query-string');
const { parseDate } = require('@/utils/parse-date');
const baseURL = 'https://www.linkresearcher.com';
@ -15,9 +15,8 @@ module.exports = async (ctx) => {
// get XSRF token from main page
const metaURL = `${baseURL}/${category}`;
const metaResponse = await got.get(metaURL);
const metaCapture = cheerio.load(metaResponse.data);
const xsrf_token = metaCapture('meta[name="_csrf"]').prop('content');
const metaResponse = await got(metaURL);
const xsrfToken = metaResponse.headers['set-cookie'][0].split(';')[0].split('=')[1];
let data = { filters: { status: false } };
if (typeof query.subject !== 'undefined' && typeof query.columns !== 'undefined') {
@ -31,16 +30,19 @@ module.exports = async (ctx) => {
title = `${title}${query.columns}`;
}
data.query = query.query;
const dataURL = `${baseURL}/api/${category}/search?from=0&size=20&type=SEARCH`;
const pageResponse = await got({
method: 'post',
url: dataURL,
const dataURL = `${baseURL}/api/${category === 'careers' ? 'articles' : category}/search`;
const pageResponse = await got.post(dataURL, {
headers: {
'content-type': 'application/json; charset=UTF-8',
'x-xsrf-token': xsrf_token,
cookie: `XSRF-TOKEN=${xsrf_token}`,
'x-xsrf-token': xsrfToken,
cookie: `XSRF-TOKEN=${xsrfToken}`,
},
data: JSON.stringify(data),
searchParams: {
from: 0,
size: 20,
type: category === 'careers' ? 'CAREER' : 'SEARCH',
},
json: data,
});
const list = pageResponse.data.hits;
@ -48,7 +50,7 @@ module.exports = async (ctx) => {
const out = list.map((item) => ({
title: item.title,
description: item.content,
pubDate: new Date(item.createdAt).toUTCString(),
pubDate: parseDate(item.createdAt, 'x'),
link: `${metaURL}/${item.id}`,
guid: `${metaURL}/${item.id}`,
doi: typeof item.identCode !== 'undefined' ? item.identCode : '',
@ -59,6 +61,7 @@ module.exports = async (ctx) => {
title: `领研 | ${title}`,
description:
'领研是链接华人学者的人才及成果平台。领研为国内外高校、科研机构及科技企业提供科研人才招聘服务,也是青年研究者的职业发展指导及线上培训平台;研究者还可将自己的研究论文上传至领研,与超过五十万华人学者分享工作的最新进展。',
image: 'https://www.linkresearcher.com/assets/images/logo-app.png',
link: baseURL,
item: out,
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:params': ['yech1990'],
};

View File

@ -0,0 +1,19 @@
module.exports = {
linkresearcher: {
_name: '领研',
'.': [
{
title: '论文',
docs: 'https://docs.rsshub.app/study.html#ling-yan',
source: ['/theses', '/information', '/careers'],
target: (_, url) => {
const pathname = new URL(url).pathname;
const searchParams = new URL(url).searchParams;
return `/linkresearcher/theses/${pathname.replace('/', '')}${searchParams.has('filters.subject') ? `&subject=${searchParams.get('filters.subject')}` : ''}${
searchParams.has('filters.columns') ? `&columns=${searchParams.get('filters.columns')}` : ''
}`;
},
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:params', require('./index'));
};