|
| 1 | +import { type CheerioAPI, load } from 'cheerio'; |
| 2 | +import { type Context } from 'hono'; |
| 3 | + |
| 4 | +import { type DataItem, type Route, type Data, ViewType } from '@/types'; |
| 5 | + |
| 6 | +import ofetch from '@/utils/ofetch'; |
| 7 | + |
| 8 | +import { rootUrl, processItems } from './util'; |
| 9 | +import InvalidParameterError from '@/errors/types/invalid-parameter'; |
| 10 | + |
| 11 | +export const handler = async (ctx: Context): Promise<Data> => { |
| 12 | + const { id } = ctx.req.param(); |
| 13 | + |
| 14 | + if (!id) { |
| 15 | + throw new InvalidParameterError('请填入合法的分类 id,参见广场 https://www.jisilu.cn/explore/'); |
| 16 | + } |
| 17 | + |
| 18 | + const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10); |
| 19 | + |
| 20 | + const targetUrl: string = new URL(`/category/${id}`, rootUrl).href; |
| 21 | + |
| 22 | + const response = await ofetch(targetUrl); |
| 23 | + const $: CheerioAPI = load(response); |
| 24 | + const language: string = $('html').prop('lang') ?? 'zh'; |
| 25 | + |
| 26 | + const items: DataItem[] = await processItems($, $('div.aw-question-list'), limit); |
| 27 | + |
| 28 | + $('div.pagination').remove(); |
| 29 | + |
| 30 | + const author = $('meta[name="keywords"]').prop('content').split(/,/)[0]; |
| 31 | + const feedImage = $('div.aw-logo img').prop('src'); |
| 32 | + |
| 33 | + return { |
| 34 | + title: `${$('title').text()} - ${$('li.active') |
| 35 | + .slice(1) |
| 36 | + .toArray() |
| 37 | + .map((l) => $(l).text()) |
| 38 | + .join('|')}`, |
| 39 | + description: $('meta[name="description"]').prop('content'), |
| 40 | + link: targetUrl, |
| 41 | + item: items, |
| 42 | + allowEmpty: true, |
| 43 | + image: feedImage, |
| 44 | + author, |
| 45 | + language, |
| 46 | + id: targetUrl, |
| 47 | + }; |
| 48 | +}; |
| 49 | + |
| 50 | +export const route: Route = { |
| 51 | + path: '/category/:id', |
| 52 | + name: '分类', |
| 53 | + url: 'www.jisilu.cn', |
| 54 | + maintainers: ['nczitzk'], |
| 55 | + handler, |
| 56 | + example: '/jisilu/category/4', |
| 57 | + parameters: { |
| 58 | + id: '分类 id,可在对应分类页 URL 中找到', |
| 59 | + }, |
| 60 | + description: `:::tip |
| 61 | +若订阅 [债券/可转债](https://www.jisilu.cn/category/4),网址为 \`https://www.jisilu.cn/category/4\`,请截取 \`https://www.jisilu.cn/category/\` 到末尾的部分 \`4\` 作为 \`id\` 参数填入,此时目标路由为 [\`/jisilu/category/4\`](https://rsshub.app/jisilu/category/4)。 |
| 62 | +::: |
| 63 | +
|
| 64 | +| 新股 | 债券/可转债 | 套利 | 其他 | 基金 | 股票 | |
| 65 | +| ---- | ----------- | ---- | ---- | ---- | ---- | |
| 66 | +| 3 | 4 | 5 | 6 | 7 | 8 | |
| 67 | +`, |
| 68 | + categories: ['finance'], |
| 69 | + features: { |
| 70 | + requireConfig: false, |
| 71 | + requirePuppeteer: false, |
| 72 | + antiCrawler: false, |
| 73 | + supportRadar: true, |
| 74 | + supportBT: false, |
| 75 | + supportPodcast: false, |
| 76 | + supportScihub: false, |
| 77 | + }, |
| 78 | + radar: [ |
| 79 | + { |
| 80 | + source: ['www.jisilu.cn/category/:id'], |
| 81 | + target: '/category/:id', |
| 82 | + }, |
| 83 | + { |
| 84 | + title: '新股', |
| 85 | + source: ['www.jisilu.cn/category/3'], |
| 86 | + target: '/category/3', |
| 87 | + }, |
| 88 | + { |
| 89 | + title: '债券/可转债', |
| 90 | + source: ['www.jisilu.cn/category/4'], |
| 91 | + target: '/category/4', |
| 92 | + }, |
| 93 | + { |
| 94 | + title: '套利', |
| 95 | + source: ['www.jisilu.cn/category/5'], |
| 96 | + target: '/category/5', |
| 97 | + }, |
| 98 | + { |
| 99 | + title: '其他', |
| 100 | + source: ['www.jisilu.cn/category/6'], |
| 101 | + target: '/category/6', |
| 102 | + }, |
| 103 | + { |
| 104 | + title: '基金', |
| 105 | + source: ['www.jisilu.cn/category/7'], |
| 106 | + target: '/category/7', |
| 107 | + }, |
| 108 | + { |
| 109 | + title: '股票', |
| 110 | + source: ['www.jisilu.cn/category/8'], |
| 111 | + target: '/category/8', |
| 112 | + }, |
| 113 | + ], |
| 114 | + view: ViewType.Articles, |
| 115 | +}; |
0 commit comments