Skip to content

Commit 1dfad55

Browse files
authored
Merge pull request #4 from DIYgod/master
[pull] master from diygod:master
2 parents ec27868 + a5f25ac commit 1dfad55

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

lib/routes/copernicium/index.ts

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { load } from 'cheerio';
66
import { parseDate } from '@/utils/parse-date';
77

88
export const route: Route = {
9-
path: '/:category',
9+
path: '/:category?',
1010
categories: ['new-media'],
1111
radar: [{ source: ['www.copernicium.tw'] }],
1212
name: '分类',
@@ -17,25 +17,33 @@ export const route: Route = {
1717
};
1818

1919
async function handler(ctx) {
20-
const CATEGORY_TO_ARG_MAP = new Map([
21-
['环球视角', '4_1'],
22-
['人文叙述', '4_3'],
23-
['观点评论', '4_5'],
24-
['专题报道', '4_7'],
25-
]);
26-
if (!CATEGORY_TO_ARG_MAP.get(ctx.req.param().category)) {
27-
throw new Error('The requested category does not exist or is not supported.');
20+
const category = ctx.req.param('category');
21+
let res;
22+
if (category) {
23+
const CATEGORY_TO_ARG_MAP = new Map([
24+
['环球视角', '4_1'],
25+
['人文叙述', '4_3'],
26+
['观点评论', '4_5'],
27+
['专题报道', '4_7'],
28+
]);
29+
if (!CATEGORY_TO_ARG_MAP.get(category)) {
30+
throw new Error('The requested category does not exist or is not supported.');
31+
}
32+
const reqArgs = {
33+
args: {
34+
_jcp: CATEGORY_TO_ARG_MAP.get(category),
35+
m31pageno: 1,
36+
},
37+
type: 0,
38+
};
39+
res = await ofetch('http://www.copernicium.tw/nr.jsp', {
40+
query: { _reqArgs: reqArgs },
41+
});
42+
} else {
43+
res = await ofetch('http://www.copernicium.tw/sys-nr/', {
44+
query: { _reqArgs: { args: {}, type: 15 } },
45+
});
2846
}
29-
const reqArgs = {
30-
args: {
31-
_jcp: CATEGORY_TO_ARG_MAP.get(ctx.req.param().category),
32-
m31pageno: 1,
33-
},
34-
type: 0,
35-
};
36-
const res = await ofetch(`https://www.copernicium.tw/nr.jsp`, {
37-
query: { _reqArgs: reqArgs },
38-
});
3947
const $ = load(res);
4048
const list = $('.J_newsResultLine a.mixNewsStyleTitle')
4149
.toArray()
@@ -60,8 +68,8 @@ async function handler(ctx) {
6068
)
6169
);
6270
return {
63-
title: `日新说 - ${ctx.req.param().category}`,
64-
link: 'https://www.copernicium.tw',
71+
title: `日新说 - ${category ?? '全部文章'}`,
72+
link: 'http://www.copernicium.tw',
6573
item: items,
6674
};
6775
}

0 commit comments

Comments
 (0)