Skip to content

Commit 6d77bd8

Browse files
syncmetaclaude
andauthored
feat(route): add 中国地质大学(北京) (#22352)
* route: add 中国地质大学(北京) Co-Authored-By: Claude <noreply@anthropic.com> * feat(route): add channel icon for 中国地质大学(北京) Co-Authored-By: Claude <noreply@anthropic.com> * fix(route): use official crest favicon as 中国地质大学(北京)feed icon Co-Authored-By: Claude <noreply@anthropic.com> * fix(route): use official high-res crest for 中国地质大学(北京)feed icon Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 42b7ee9 commit 6d77bd8

3 files changed

Lines changed: 180 additions & 0 deletions

File tree

lib/routes/cugb/jwc.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { load } from 'cheerio';
2+
3+
import type { Data, DataItem, Route } from '@/types';
4+
import cache from '@/utils/cache';
5+
import got from '@/utils/got';
6+
import { parseDate } from '@/utils/parse-date';
7+
import timezone from '@/utils/timezone';
8+
9+
const rootUrl = 'https://jwc.cugb.edu.cn';
10+
11+
const channels: Record<string, string> = {
12+
xszq: '学生专区',
13+
};
14+
15+
export const route: Route = {
16+
path: '/jwc/:channel?',
17+
categories: ['university'],
18+
example: '/cugb/jwc/xszq',
19+
parameters: { channel: '栏目,默认为 `xszq` 学生专区' },
20+
features: {
21+
requireConfig: false,
22+
requirePuppeteer: false,
23+
antiCrawler: false,
24+
supportBT: false,
25+
supportPodcast: false,
26+
supportScihub: false,
27+
},
28+
radar: [
29+
{
30+
source: ['jwc.cugb.edu.cn/:channel'],
31+
target: '/jwc/:channel',
32+
},
33+
],
34+
name: '教务处',
35+
maintainers: ['syncmeta'],
36+
handler,
37+
};
38+
39+
async function handler(ctx): Promise<Data> {
40+
const channel = ctx.req.param('channel') ?? 'xszq';
41+
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;
42+
const listUrl = `${rootUrl}/${channel}/`;
43+
44+
const { data: response } = await got(listUrl);
45+
const $ = load(response);
46+
47+
const list: DataItem[] = $('li a')
48+
.toArray()
49+
.map((el) => {
50+
const item = $(el);
51+
const title = item.find('.list_con_main').text().trim();
52+
return {
53+
title,
54+
link: new URL(item.attr('href') as string, rootUrl).href,
55+
pubDate: timezone(parseDate(item.find('.list_con_time').text().trim()), 8),
56+
};
57+
})
58+
.filter((item) => item.title)
59+
.slice(0, limit);
60+
61+
const items = (await Promise.all(
62+
list.map((item) =>
63+
cache.tryGet(item.link as string, async () => {
64+
const { data: detailResponse } = await got(item.link as string);
65+
const content = load(detailResponse);
66+
item.description = content('div.detail_content_box').html() ?? '';
67+
return item;
68+
})
69+
)
70+
)) as DataItem[];
71+
72+
return {
73+
title: `中国地质大学(北京)教务处 - ${channels[channel] ?? channel}`,
74+
link: listUrl,
75+
item: items,
76+
language: 'zh-CN',
77+
image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
78+
icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
79+
logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
80+
};
81+
}

lib/routes/cugb/namespace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Namespace } from '@/types';
2+
3+
export const namespace: Namespace = {
4+
name: 'China University of Geosciences (Beijing)',
5+
url: 'cugb.edu.cn',
6+
categories: ['university'],
7+
description: '',
8+
lang: 'zh-CN',
9+
10+
zh: {
11+
name: '中国地质大学(北京)',
12+
},
13+
};

lib/routes/cugb/news.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { load } from 'cheerio';
2+
3+
import type { Data, DataItem, Route } from '@/types';
4+
import cache from '@/utils/cache';
5+
import got from '@/utils/got';
6+
import { parseDate } from '@/utils/parse-date';
7+
import timezone from '@/utils/timezone';
8+
9+
const rootUrl = 'https://www.cugb.edu.cn';
10+
11+
const channels: Record<string, string> = {
12+
bdxw: '北地新闻',
13+
};
14+
15+
export const route: Route = {
16+
path: '/news/:channel?',
17+
categories: ['university'],
18+
example: '/cugb/news/bdxw',
19+
parameters: { channel: '栏目,默认为 `bdxw` 北地新闻' },
20+
features: {
21+
requireConfig: false,
22+
requirePuppeteer: false,
23+
antiCrawler: false,
24+
supportBT: false,
25+
supportPodcast: false,
26+
supportScihub: false,
27+
},
28+
radar: [
29+
{
30+
source: ['www.cugb.edu.cn/:channel.jhtml'],
31+
target: '/news/:channel',
32+
},
33+
],
34+
name: '校园新闻',
35+
maintainers: ['syncmeta'],
36+
handler,
37+
};
38+
39+
async function handler(ctx): Promise<Data> {
40+
const channel = ctx.req.param('channel') ?? 'bdxw';
41+
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;
42+
const listUrl = `${rootUrl}/${channel}.jhtml`;
43+
44+
const { data: response } = await got(listUrl);
45+
const $ = load(response);
46+
47+
const list: DataItem[] = $('li a.con')
48+
.toArray()
49+
.slice(0, limit)
50+
.map((el) => {
51+
const item = $(el);
52+
const [date, author] = item
53+
.find('span')
54+
.text()
55+
.trim()
56+
.split('|')
57+
.map((s) => s.trim());
58+
return {
59+
title: item.find('h3.tit').text().trim(),
60+
link: new URL(item.attr('href') as string, rootUrl).href,
61+
pubDate: timezone(parseDate(date), 8),
62+
author,
63+
};
64+
});
65+
66+
const items = (await Promise.all(
67+
list.map((item) =>
68+
cache.tryGet(item.link as string, async () => {
69+
const { data: detailResponse } = await got(item.link as string);
70+
const content = load(detailResponse);
71+
item.description = content('div.postbody').html() ?? '';
72+
return item;
73+
})
74+
)
75+
)) as DataItem[];
76+
77+
return {
78+
title: `中国地质大学(北京) - ${channels[channel] ?? channel}`,
79+
link: listUrl,
80+
item: items,
81+
language: 'zh-CN',
82+
image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
83+
icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
84+
logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
85+
};
86+
}

0 commit comments

Comments
 (0)