Skip to content

Commit 06a995b

Browse files
authored
feat(routes): Add censorbib (#15082)
* feat(routes): Add censorbib * fix: Make got options optional * Update lib/routes/nymity/censorbib.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> ---------
1 parent 8e9cccb commit 06a995b

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

lib/routes/nymity/censorbib.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { DataItem, Route } from '@/types';
2+
import got from '@/utils/got';
3+
import { load } from 'cheerio';
4+
const url = 'https://censorbib.nymity.ch/';
5+
6+
export const route: Route = {
7+
path: '/censorbib',
8+
categories: ['journal'],
9+
example: '/nymity/censorbib',
10+
radar: [
11+
{
12+
source: ['censorbib.nymity.ch/'],
13+
},
14+
],
15+
name: 'CensorBib Updates',
16+
maintainers: ['xtexChooser'],
17+
handler,
18+
url: 'censorbib.nymity.ch/',
19+
};
20+
21+
async function handler() {
22+
const resp = await got.get(url);
23+
24+
const $ = load(resp.data);
25+
const items = $('#container ul li')
26+
.toArray()
27+
.map((item): DataItem => {
28+
const c = $(item);
29+
const id = c.attr('id')!;
30+
const title = c.find('span.paper').text().trim();
31+
const author = c.find('span.author').text().trim();
32+
const other = c.find('span.other').text().trim();
33+
const download = c.find("img.icon[title='Download paper']").parent().attr('href');
34+
const downloadBibTex = c.find("img.icon[title='Download BibTeX']").parent().attr('href');
35+
const linkToPaper = c.find("img.icon[title='Link to paper']").parent().attr('href');
36+
return {
37+
title,
38+
description: `${other}<br/><br/><a href='${download}'>Download</a><br/><a href='${downloadBibTex}'>Download BibTex</a>`,
39+
author,
40+
guid: id,
41+
link: linkToPaper,
42+
};
43+
});
44+
45+
return {
46+
title: 'CensorBib',
47+
link: url,
48+
description: 'CensorBib Updates',
49+
item: items,
50+
};
51+
}

lib/routes/nymity/namespace.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Namespace } from '@/types';
2+
3+
export const namespace: Namespace = {
4+
name: 'nymity',
5+
url: 'censorbib.nymity.ch',
6+
};

lib/utils/got.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ const getFakeGot = (defaultOptions?: any) => {
6464
return response;
6565
};
6666

67-
fakeGot.get = (request, options) => fakeGot(request, { ...options, method: 'GET' });
68-
fakeGot.post = (request, options) => fakeGot(request, { ...options, method: 'POST' });
69-
fakeGot.put = (request, options) => fakeGot(request, { ...options, method: 'PUT' });
70-
fakeGot.patch = (request, options) => fakeGot(request, { ...options, method: 'PATCH' });
71-
fakeGot.head = (request, options) => fakeGot(request, { ...options, method: 'HEAD' });
72-
fakeGot.delete = (request, options) => fakeGot(request, { ...options, method: 'DELETE' });
67+
fakeGot.get = (request, options?) => fakeGot(request, { ...options, method: 'GET' });
68+
fakeGot.post = (request, options?) => fakeGot(request, { ...options, method: 'POST' });
69+
fakeGot.put = (request, options?) => fakeGot(request, { ...options, method: 'PUT' });
70+
fakeGot.patch = (request, options?) => fakeGot(request, { ...options, method: 'PATCH' });
71+
fakeGot.head = (request, options?) => fakeGot(request, { ...options, method: 'HEAD' });
72+
fakeGot.delete = (request, options?) => fakeGot(request, { ...options, method: 'DELETE' });
7373
fakeGot.extend = (options) => getFakeGot(options);
7474

7575
return fakeGot;

0 commit comments

Comments
 (0)