|
| 1 | +import { Route } from '@/types'; |
| 2 | +import { getCurrentPath } from '@/utils/helpers'; |
| 3 | +const __dirname = getCurrentPath(import.meta.url); |
| 4 | + |
| 5 | +import { parseDate } from '@/utils/parse-date'; |
| 6 | +import { art } from '@/utils/render'; |
| 7 | +import path from 'node:path'; |
| 8 | +import parser from '@/utils/rss-parser'; |
| 9 | + |
| 10 | +const pdfUrlGenerators = { |
| 11 | + arxiv: (id: string) => `https://arxiv.org/pdf/${id}.pdf`, |
| 12 | +}; |
| 13 | + |
| 14 | +export const handler = async (ctx) => { |
| 15 | + const { keyword = 'query/Detection' } = ctx.req.param(); |
| 16 | + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 150; |
| 17 | + |
| 18 | + const rootUrl = 'https://papers.cool'; |
| 19 | + const currentUrl = new URL(`arxiv/search?highlight=1&query=${keyword}&sort=0`, rootUrl).href; |
| 20 | + const feedUrl = new URL(`arxiv/search/feed?query=${keyword}`, rootUrl).href; |
| 21 | + |
| 22 | + const site = keyword.split(/\//)[0]; |
| 23 | + const apiKimiUrl = new URL(`${site}/kimi?paper=`, rootUrl).href; |
| 24 | + const feed = await parser.parseURL(feedUrl); |
| 25 | + |
| 26 | + const language = 'en'; |
| 27 | + |
| 28 | + const items = feed.items.slice(0, limit).map((item) => { |
| 29 | + const title = item.title; |
| 30 | + const guid = item.guid; |
| 31 | + |
| 32 | + const id = item.link?.split(/\//).pop() ?? ''; |
| 33 | + const kimiUrl = new URL(id, apiKimiUrl).href; |
| 34 | + const pdfUrl = Object.hasOwn(pdfUrlGenerators, site) ? pdfUrlGenerators[site](id) : undefined; |
| 35 | + |
| 36 | + const authorString = item.author; |
| 37 | + const description = art(path.join(__dirname, 'templates/description.art'), { |
| 38 | + pdfUrl, |
| 39 | + siteUrl: item.link, |
| 40 | + kimiUrl, |
| 41 | + authorString, |
| 42 | + summary: item.summary, |
| 43 | + }); |
| 44 | + |
| 45 | + return { |
| 46 | + title, |
| 47 | + description, |
| 48 | + pubDate: parseDate(item.pubDate ?? ''), |
| 49 | + link: item.link, |
| 50 | + category: item.categories, |
| 51 | + author: authorString, |
| 52 | + doi: `${site}${id}`, |
| 53 | + guid, |
| 54 | + id: guid, |
| 55 | + content: { |
| 56 | + html: description, |
| 57 | + text: item.content, |
| 58 | + }, |
| 59 | + language, |
| 60 | + enclosure_url: pdfUrl, |
| 61 | + enclosure_type: 'application/pdf', |
| 62 | + enclosure_title: title, |
| 63 | + }; |
| 64 | + }); |
| 65 | + |
| 66 | + return { |
| 67 | + title: feed.title, |
| 68 | + description: feed.description, |
| 69 | + link: currentUrl, |
| 70 | + item: items, |
| 71 | + allowEmpty: true, |
| 72 | + image: feed.image?.url, |
| 73 | + language: feed.language, |
| 74 | + }; |
| 75 | +}; |
| 76 | + |
| 77 | +export const route: Route = { |
| 78 | + path: '/query/:keyword{.+}?', |
| 79 | + name: 'Topic', |
| 80 | + url: 'papers.cool', |
| 81 | + maintainers: ['Muyun99'], |
| 82 | + handler, |
| 83 | + example: '/papers/query/Detection', |
| 84 | + parameters: { keyword: 'Keyword to search for papers, e.g., Detection, Segmentation, etc.' }, |
| 85 | + description: `:::tip |
| 86 | + If you subscibe to [arXiv Paper queryed by Detection](https://papers.cool/arxiv/search?highlight=1&query=Detection), where the URL is \`https://papers.cool/arxiv/search?highlight=1&query=Detection\`, extract the part \`https://papers.cool/\` to the end, and use it as the parameter to fill in. Therefore, the route will be [\`/papers/query/Detection\`](https://rsshub.app/papers/query/Detection). |
| 87 | + ::: |
| 88 | +
|
| 89 | + | Category | id | |
| 90 | + | ----------------------------------------------------- | ------------------- | |
| 91 | + | arXiv Paper queryed by Detection | query/Detection | |
| 92 | + | arXiv Paper queryed by Segmentation | query/Segmentation | |
| 93 | + `, |
| 94 | + categories: ['journal'], |
| 95 | + |
| 96 | + features: { |
| 97 | + requireConfig: false, |
| 98 | + requirePuppeteer: false, |
| 99 | + antiCrawler: false, |
| 100 | + supportRadar: true, |
| 101 | + supportBT: false, |
| 102 | + supportPodcast: false, |
| 103 | + supportScihub: true, |
| 104 | + }, |
| 105 | + radar: [ |
| 106 | + { |
| 107 | + title: 'arXiv Paper queryed by Keyword', |
| 108 | + source: ['papers.cool/arxiv/search?highlight=1&query=*&sort=0'], |
| 109 | + target: '/papers/query/:keyword', |
| 110 | + }, |
| 111 | + ], |
| 112 | +}; |
0 commit comments