-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): Add 国家哲学社会科学文献中心 (#14737)
* feat(route) Add 国家哲学社会科学文献中心 * Adapt to new namespace * Update lib/routes/ncpssd/newlist.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/ncpssd/newlist.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/ncpssd/newlist.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/ncpssd/newlist.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/ncpssd/newlist.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: cr ---------
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '国家哲学社会科学文献中心', | ||
url: 'ncpssd.cn', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import { Route } from '@/types'; | ||
|
||
export const route: Route = { | ||
path: '/newlist', | ||
categories: ['study'], | ||
example: '/ncpssd/newlist', | ||
radar: [ | ||
{ | ||
source: ['ncpssd.cn/', 'ncpssd.cn/newlist'], | ||
}, | ||
], | ||
name: '最新文献', | ||
maintainers: ['LyleLee'], | ||
handler, | ||
url: 'ncpssd.cn/', | ||
}; | ||
|
||
async function handler() { | ||
const baseUrl = 'https://www.ncpssd.cn'; | ||
const argument = '/newlist?type=0'; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: baseUrl + argument, | ||
}); | ||
|
||
const data = response.data; | ||
const $ = load(data); | ||
const items = $('.news-list > li'); | ||
|
||
const list = items.toArray().map((p) => { | ||
const title = $(p) | ||
.find('a') | ||
.text() | ||
.replaceAll(/(\r\n|\n|\r)/gm, '') | ||
.trim(); | ||
const articleUrl = | ||
baseUrl + | ||
$(p) | ||
.find('a') | ||
.attr('onclick') | ||
?.match(/\('(.*?)'\)/)?.[1]; | ||
const parseUrl = new URL(articleUrl); | ||
|
||
return { | ||
title, | ||
link: articleUrl, | ||
lngid: parseUrl.searchParams.get('id'), | ||
type: parseUrl.searchParams.get('typename'), | ||
pageType: parseUrl.searchParams.get('nav'), | ||
}; | ||
}); | ||
|
||
const paper = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const url = 'https://www.ncpssd.cn/articleinfoHandler/getjournalarticletable'; // Adjust the URL accordingly | ||
const headers = { | ||
Accept: 'application/json, text/javascript, */*; q=0.01', | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}; | ||
|
||
const requestBody = { | ||
lngid: item.lngid, | ||
type: item.type, | ||
pageType: item.pageType, | ||
}; | ||
|
||
const response = await got.post(url, { | ||
headers, | ||
json: requestBody, | ||
responseType: 'json', // Set the expected response type | ||
}); | ||
|
||
return { | ||
title: item.title, | ||
link: item.link, | ||
author: response.data.data.showwriter, | ||
description: response.data.data.remarkc, | ||
pubDate: parseDate(response.data.data.publishDateTime), | ||
}; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
// 源标题 | ||
title: '国家哲学社会科学文献中心', | ||
// 源链接 | ||
link: baseUrl + argument, | ||
// 源文章 | ||
item: paper, | ||
}; | ||
} |