Skip to content

Commit 5e35c3f

Browse files
authored
feat(route): add 集思录广场 (#17972)
* feat(route): add 集思录广场 * fix typo
1 parent 7c2ea37 commit 5e35c3f

File tree

7 files changed

+477
-133
lines changed

7 files changed

+477
-133
lines changed

lib/routes/jisilu/category.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
};

lib/routes/jisilu/explore.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
10+
export const handler = async (ctx: Context): Promise<Data> => {
11+
const { filter } = ctx.req.param();
12+
const limit: number = Number.parseInt(ctx.req.query('limit') ?? '30', 10);
13+
14+
const targetUrl: string = new URL(`/${filter ? 'home/' : ''}explore/${filter ?? ''}`, rootUrl).href;
15+
16+
const response = await ofetch(targetUrl);
17+
const $: CheerioAPI = load(response);
18+
const language: string = $('html').prop('lang') ?? 'zh';
19+
20+
const items: DataItem[] = await processItems($, $('div.aw-question-list'), limit);
21+
22+
$('div.pagination').remove();
23+
24+
const author = $('meta[name="keywords"]').prop('content').split(/,/)[0];
25+
const feedImage = $('div.aw-logo img').prop('src');
26+
27+
return {
28+
title: `${$('title').text()} - ${$('li.active')
29+
.slice(1)
30+
.toArray()
31+
.map((l) => $(l).text())
32+
.join('|')}`,
33+
description: $('meta[name="description"]').prop('content'),
34+
link: targetUrl,
35+
item: items,
36+
allowEmpty: true,
37+
image: feedImage,
38+
author,
39+
language,
40+
id: targetUrl,
41+
};
42+
};
43+
44+
export const route: Route = {
45+
path: '/explore/:filter?',
46+
name: '广场',
47+
url: 'www.jisilu.cn',
48+
maintainers: ['nczitzk'],
49+
handler,
50+
example: '/jisilu/explore',
51+
parameters: {
52+
category: '过滤器,默认为空,可在对应页 URL 中找到',
53+
},
54+
description: `:::tip
55+
若订阅 [债券/可转债 - 热门 - 30天](https://www.jisilu.cn/home/explore/category-4__sort_type-hot__day-30),网址为 \`https://www.jisilu.cn/home/explore/category-4__sort_type-hot__day-30\`,请截取 \`https://www.jisilu.cn/home/explore/\` 到末尾的部分 \`category-4__sort_type-hot__day-30\` 作为 \`filter\` 参数填入,此时目标路由为 [\`/jisilu/explore/category-4__sort_type-hot__day-30\`](https://rsshub.app/jisilu/explore/category-4__sort_type-hot__day-30)。
56+
:::
57+
`,
58+
categories: ['finance'],
59+
features: {
60+
requireConfig: false,
61+
requirePuppeteer: false,
62+
antiCrawler: false,
63+
supportRadar: true,
64+
supportBT: false,
65+
supportPodcast: false,
66+
supportScihub: false,
67+
},
68+
radar: [
69+
{
70+
source: ['www.jisilu.cn/home/explore/:filter', 'www.jisilu.cn/home/explore', 'www.jisilu.cn/explore'],
71+
target: (params) => {
72+
const filter = params.filter;
73+
74+
return `/jisilu/explore${filter ? `/${filter}` : ''}`;
75+
},
76+
},
77+
],
78+
view: ViewType.Articles,
79+
};

lib/routes/jisilu/index.ts

Lines changed: 0 additions & 133 deletions
This file was deleted.

lib/routes/jisilu/namespace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import type { Namespace } from '@/types';
33
export const namespace: Namespace = {
44
name: '集思录',
55
url: 'jisilu.cn',
6+
description: '一个以数据为本的投资社区',
67
lang: 'zh-CN',
78
};

0 commit comments

Comments
 (0)