Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Cool Papers #14129

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions lib/v2/papers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');

module.exports = async (ctx) => {
const { category = 'arxiv/cs.CL' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 150;

const rootUrl = 'https://papers.cool';
const currentUrl = new URL(category, rootUrl).href;

const site = category.split(/\//)[0];
const apiKimiUrl = new URL(`${site}/kimi/`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

const pubDate = parseDate(
$('p.info')
.first()
.text()
.match(/(\d+\s\w+\s\d{4})/)[1],
['DD MMM YYYY', 'D MMM YYYY']
);

const items = $('div.panel')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const id = item.prop('id');
const kimiUrl = new URL(id, apiKimiUrl).href;
const enclosureUrl =
item
.find('a.pdf-preview')
.prop('onclick')
.match(/'(http.*?)'/)?.[1] ?? undefined;

return {
title: item.find('span[id]').first().text(),
link: kimiUrl,
description: art(path.join(__dirname, 'templates/description.art'), {
kimiUrl,
siteUrl: item.find('a').first().prop('href'),
pdfUrl: enclosureUrl,
summary: item.find('p.summary').text(),
}),
author: item
.find('p.authors a')
.toArray()
.map((a) => $(a).text())
.join('; '),
guid: `${currentUrl}#${id}`,
pubDate,
enclosure_url: enclosureUrl,
enclosure_type: enclosureUrl ? 'application/pdf' : undefined,
};
});

const title = $('title').text();
const icon = new URL('favicon.ico', rootUrl).href;

ctx.state.data = {
item: items,
title: title.split(/-/)[0].trim(),
link: currentUrl,
description: title,
icon,
logo: icon,
subtitle: $('h1').first().text(),
};
};
3 changes: 3 additions & 0 deletions lib/v2/papers/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
17 changes: 17 additions & 0 deletions lib/v2/papers/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
'papers.cool': {
_name: 'Cool Papers',
'.': [
{
title: 'Category',
docs: 'https://docs.rsshub.app/routes/journal#cool-papers-category',
source: ['/:category*'],
target: (params) => {
const category = params.category;

return `/papers${category ? `/${category}` : ''}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/papers/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:category*', require('./'));
};
15 changes: 15 additions & 0 deletions lib/v2/papers/templates/description.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ if pdfUrl }}
<a href="{{ pdfUrl }}">[PDF]</a>
{{ /if }}

{{ if siteUrl }}
<a href="{{ siteUrl }}">[Site]</a>
{{ /if }}

{{ if kimiUrl }}
<a href="{{ kimiUrl }}">[Kimi]</a>
{{ /if }}

{{ if summary }}
<p>{{ summary }}</p>
{{ /if }}
15 changes: 15 additions & 0 deletions website/docs/routes/journal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@
Including 'cell', 'cancer-cell', 'cell-chemical-biology', 'cell-host-microbe', 'cell-metabolism', 'cell-reports', 'cell-reports-physical-science', 'cell-stem-cell', 'cell-systems', 'chem', 'current-biology', 'developmental-cell', 'immunity', 'joule', 'matter', 'molecular-cell', 'neuron', 'one-earth' and 'structure'.
</Route>

## Cool Papers {#cool-papers}

### Category {#cool-papers-category}

<Route author="nczitzk" example="/papers" path="/papers/:category?" paramsDesc={['Category, see below, `arxiv/cs.CL` by default']} radar="1" supportBT="1" supportScihub="1">
| Category | id |
| ----------------------------------------------------- | ----------- |
| Arxiv Computation and Language (cs.CL) | arxiv/cs.CL |
| Arxiv Machine Learning (cs.LG) | arxiv/cs.CL |
| Arxiv Artificial Intelligence (cs.AI) | arxiv/cs.CL |
| Arxiv Information Retrieval (cs.IR) | arxiv/cs.CL |
| Arxiv Computer Vision and Pattern Recognition (cs.CV) | arxiv/cs.CL |
| Arxiv Machine Learning (stat.ML) | arxiv/cs.CL |
nczitzk marked this conversation as resolved.
Show resolved Hide resolved
</Route>

## Deloitte {#deloitte}

### Articles {#deloitte-articles}
Expand Down