mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
feat: add arxiv search (#4859)
This commit is contained in:
@@ -4,6 +4,18 @@ pageClass: routes
|
|||||||
|
|
||||||
# 科学期刊
|
# 科学期刊
|
||||||
|
|
||||||
|
## arXiv
|
||||||
|
|
||||||
|
### 搜索关键字
|
||||||
|
|
||||||
|
<Route author="nczitzk" example="/arxiv/search_query=all:electron&start=0&max_results=10" path="/arxiv/:query" :paramsDesc="['查询语句']" anticrawler="1">
|
||||||
|
|
||||||
|
参见 [arXiv API 用户手册](https://arxiv.org/help/api/user-manual) 查看所有查询参数。
|
||||||
|
|
||||||
|
路由中的参数 query 处填写 `http://export.arxiv.org/api/query?` 后的内容。
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## Cell
|
## Cell
|
||||||
|
|
||||||
### 主刊
|
### 主刊
|
||||||
|
|||||||
@@ -2768,4 +2768,7 @@ router.get('/stork/keyword/:trackID/:displayKey', require('./routes/stork/keywor
|
|||||||
// 致美化
|
// 致美化
|
||||||
router.get('/zhutix/latest', require('./routes/zhutix/latest'));
|
router.get('/zhutix/latest', require('./routes/zhutix/latest'));
|
||||||
|
|
||||||
|
// arXiv
|
||||||
|
router.get('/arxiv/:query', require('./routes/arxiv/query'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
28
lib/routes/arxiv/query.js
Normal file
28
lib/routes/arxiv/query.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const currentUrl = `http://export.arxiv.org/api/query?${ctx.params.query}`;
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: currentUrl,
|
||||||
|
});
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const list = $('entry')
|
||||||
|
.map((_, item) => {
|
||||||
|
item = $(item);
|
||||||
|
return {
|
||||||
|
title: item.find('title').text(),
|
||||||
|
link: item.find('link[type="text/html"]').attr('href'),
|
||||||
|
pubDate: new Date(item.find('published').text()).toUTCString(),
|
||||||
|
description: item.find('summary').text(),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get();
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: 'arXiv (' + ctx.params.query + ')',
|
||||||
|
link: currentUrl,
|
||||||
|
item: list,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user