diff --git a/docs/journal.md b/docs/journal.md index b67ca7ed90..92a0fbc343 100644 --- a/docs/journal.md +++ b/docs/journal.md @@ -4,6 +4,18 @@ pageClass: routes # 科学期刊 +## arXiv + +### 搜索关键字 + + + +参见 [arXiv API 用户手册](https://arxiv.org/help/api/user-manual) 查看所有查询参数。 + +路由中的参数 query 处填写 `http://export.arxiv.org/api/query?` 后的内容。 + + + ## Cell ### 主刊 diff --git a/lib/router.js b/lib/router.js index 4b7792a04a..64bfa9647e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2768,4 +2768,7 @@ router.get('/stork/keyword/:trackID/:displayKey', require('./routes/stork/keywor // 致美化 router.get('/zhutix/latest', require('./routes/zhutix/latest')); +// arXiv +router.get('/arxiv/:query', require('./routes/arxiv/query')); + module.exports = router; diff --git a/lib/routes/arxiv/query.js b/lib/routes/arxiv/query.js new file mode 100644 index 0000000000..af519be77c --- /dev/null +++ b/lib/routes/arxiv/query.js @@ -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, + }; +};