Skip to content

Commit

Permalink
Merge pull request #116 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Dec 29, 2023
2 parents 58f0c4e + 1fb2ddf commit 6f9550f
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
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.LG |
| Arxiv Artificial Intelligence (cs.AI) | arxiv/cs.AI |
| Arxiv Information Retrieval (cs.IR) | arxiv/cs.IR |
| Arxiv Computer Vision and Pattern Recognition (cs.CV) | arxiv/cs.CV |
| Arxiv Machine Learning (stat.ML) | arxiv/stat.ML |
</Route>

## Deloitte {#deloitte}

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

0 comments on commit 6f9550f

Please sign in to comment.