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>
This commit is contained in:
parent
42b7ee9b7c
commit
6d77bd84c0
|
|
@ -0,0 +1,81 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Data, DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const rootUrl = 'https://jwc.cugb.edu.cn';
|
||||
|
||||
const channels: Record<string, string> = {
|
||||
xszq: '学生专区',
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/jwc/:channel?',
|
||||
categories: ['university'],
|
||||
example: '/cugb/jwc/xszq',
|
||||
parameters: { channel: '栏目,默认为 `xszq` 学生专区' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['jwc.cugb.edu.cn/:channel'],
|
||||
target: '/jwc/:channel',
|
||||
},
|
||||
],
|
||||
name: '教务处',
|
||||
maintainers: ['syncmeta'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx): Promise<Data> {
|
||||
const channel = ctx.req.param('channel') ?? 'xszq';
|
||||
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;
|
||||
const listUrl = `${rootUrl}/${channel}/`;
|
||||
|
||||
const { data: response } = await got(listUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const list: DataItem[] = $('li a')
|
||||
.toArray()
|
||||
.map((el) => {
|
||||
const item = $(el);
|
||||
const title = item.find('.list_con_main').text().trim();
|
||||
return {
|
||||
title,
|
||||
link: new URL(item.attr('href') as string, rootUrl).href,
|
||||
pubDate: timezone(parseDate(item.find('.list_con_time').text().trim()), 8),
|
||||
};
|
||||
})
|
||||
.filter((item) => item.title)
|
||||
.slice(0, limit);
|
||||
|
||||
const items = (await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link as string, async () => {
|
||||
const { data: detailResponse } = await got(item.link as string);
|
||||
const content = load(detailResponse);
|
||||
item.description = content('div.detail_content_box').html() ?? '';
|
||||
return item;
|
||||
})
|
||||
)
|
||||
)) as DataItem[];
|
||||
|
||||
return {
|
||||
title: `中国地质大学(北京)教务处 - ${channels[channel] ?? channel}`,
|
||||
link: listUrl,
|
||||
item: items,
|
||||
language: 'zh-CN',
|
||||
image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import type { Namespace } from '@/types';
|
||||
|
||||
export const namespace: Namespace = {
|
||||
name: 'China University of Geosciences (Beijing)',
|
||||
url: 'cugb.edu.cn',
|
||||
categories: ['university'],
|
||||
description: '',
|
||||
lang: 'zh-CN',
|
||||
|
||||
zh: {
|
||||
name: '中国地质大学(北京)',
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
import { load } from 'cheerio';
|
||||
|
||||
import type { Data, DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
|
||||
const rootUrl = 'https://www.cugb.edu.cn';
|
||||
|
||||
const channels: Record<string, string> = {
|
||||
bdxw: '北地新闻',
|
||||
};
|
||||
|
||||
export const route: Route = {
|
||||
path: '/news/:channel?',
|
||||
categories: ['university'],
|
||||
example: '/cugb/news/bdxw',
|
||||
parameters: { channel: '栏目,默认为 `bdxw` 北地新闻' },
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['www.cugb.edu.cn/:channel.jhtml'],
|
||||
target: '/news/:channel',
|
||||
},
|
||||
],
|
||||
name: '校园新闻',
|
||||
maintainers: ['syncmeta'],
|
||||
handler,
|
||||
};
|
||||
|
||||
async function handler(ctx): Promise<Data> {
|
||||
const channel = ctx.req.param('channel') ?? 'bdxw';
|
||||
const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20;
|
||||
const listUrl = `${rootUrl}/${channel}.jhtml`;
|
||||
|
||||
const { data: response } = await got(listUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const list: DataItem[] = $('li a.con')
|
||||
.toArray()
|
||||
.slice(0, limit)
|
||||
.map((el) => {
|
||||
const item = $(el);
|
||||
const [date, author] = item
|
||||
.find('span')
|
||||
.text()
|
||||
.trim()
|
||||
.split('|')
|
||||
.map((s) => s.trim());
|
||||
return {
|
||||
title: item.find('h3.tit').text().trim(),
|
||||
link: new URL(item.attr('href') as string, rootUrl).href,
|
||||
pubDate: timezone(parseDate(date), 8),
|
||||
author,
|
||||
};
|
||||
});
|
||||
|
||||
const items = (await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link as string, async () => {
|
||||
const { data: detailResponse } = await got(item.link as string);
|
||||
const content = load(detailResponse);
|
||||
item.description = content('div.postbody').html() ?? '';
|
||||
return item;
|
||||
})
|
||||
)
|
||||
)) as DataItem[];
|
||||
|
||||
return {
|
||||
title: `中国地质大学(北京) - ${channels[channel] ?? channel}`,
|
||||
link: listUrl,
|
||||
item: items,
|
||||
language: 'zh-CN',
|
||||
image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png',
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue