Skip to content

Commit

Permalink
feat(route/copernicium): Add default (#17828)
Browse files Browse the repository at this point in the history
* feat(route/copernicium): Add default

* Update index.ts

* Update index.ts

* Update lib/routes/copernicium/index.ts

Co-authored-by: Tony <[email protected]>

* Update index.ts

* Update index.ts

* Update lib/routes/copernicium/index.ts
---------
  • Loading branch information
dzx-dzx authored Dec 21, 2024
1 parent 43a505f commit a5f25ac
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions lib/routes/copernicium/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const route: Route = {
path: '/:category',
path: '/:category?',
categories: ['new-media'],
radar: [{ source: ['www.copernicium.tw'] }],
name: '分类',
Expand All @@ -17,25 +17,33 @@ export const route: Route = {
};

async function handler(ctx) {
const CATEGORY_TO_ARG_MAP = new Map([
['环球视角', '4_1'],
['人文叙述', '4_3'],
['观点评论', '4_5'],
['专题报道', '4_7'],
]);
if (!CATEGORY_TO_ARG_MAP.get(ctx.req.param().category)) {
throw new Error('The requested category does not exist or is not supported.');
const category = ctx.req.param('category');
let res;
if (category) {
const CATEGORY_TO_ARG_MAP = new Map([
['环球视角', '4_1'],
['人文叙述', '4_3'],
['观点评论', '4_5'],
['专题报道', '4_7'],
]);
if (!CATEGORY_TO_ARG_MAP.get(category)) {
throw new Error('The requested category does not exist or is not supported.');
}
const reqArgs = {
args: {
_jcp: CATEGORY_TO_ARG_MAP.get(category),
m31pageno: 1,
},
type: 0,
};
res = await ofetch('http://www.copernicium.tw/nr.jsp', {
query: { _reqArgs: reqArgs },
});
} else {
res = await ofetch('http://www.copernicium.tw/sys-nr/', {
query: { _reqArgs: { args: {}, type: 15 } },
});
}
const reqArgs = {
args: {
_jcp: CATEGORY_TO_ARG_MAP.get(ctx.req.param().category),
m31pageno: 1,
},
type: 0,
};
const res = await ofetch(`https://www.copernicium.tw/nr.jsp`, {
query: { _reqArgs: reqArgs },
});
const $ = load(res);
const list = $('.J_newsResultLine a.mixNewsStyleTitle')
.toArray()
Expand All @@ -60,8 +68,8 @@ async function handler(ctx) {
)
);
return {
title: `日新说 - ${ctx.req.param().category}`,
link: 'https://www.copernicium.tw',
title: `日新说 - ${category ?? '全部文章'}`,
link: 'http://www.copernicium.tw',
item: items,
};
}

0 comments on commit a5f25ac

Please sign in to comment.