feat(route): add new route for NYCU (#20214)

* Add 國立陽明交通大學

* ensure timezone

* Update lib/routes/nycu/aa.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/announcement.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/cs.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/osa.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/osa.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/aa.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/announcement.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/routes/nycu/cs.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* remove unrelated description

* remove hardcoded number

* fix the for loop

* fix typo

---------
This commit is contained in:
SimbaFs
2025-10-03 04:37:06 +08:00
committed by GitHub
co-authored by Tony
parent 14a47cd996
commit ae08e37452
5 changed files with 304 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
import { Data, Route } from '@/types';
import timezone from '@/utils/timezone';
import { CheerioAPI, load } from 'cheerio';
import { Context } from 'hono';
import ofetch from '@/utils/ofetch';
function ROCDate(dateStr: string | Date): Date {
const date = new Date(dateStr);
date.setFullYear(date.getFullYear() + 1911);
return timezone(date, 8);
}
async function handler(ctx: Context): Promise<Data> {
const id = ctx.req.param('id') ?? '2652';
const url = `https://aa.nycu.edu.tw/aa/ch/app/news/list?module=headnews&id=${id}`;
const name = {
'2652': '全部',
'2462': '註冊組',
'2502': '課務組',
'2523': '綜合組',
'2538': '實習組',
'2545': '數位教學中心',
'2565': '教學發展中心',
'2617': '國際高教培訓暨認證中心',
'2638': '雙語教育與學習推動辦公室',
}[id];
const $ = await ofetch<CheerioAPI>(url, {
parseResponse: load,
});
const item = $('.newslist li')
.toArray()
.map((e) => ({
title: $('a', e).attr('title')?.trim() || '',
link: $('a', e).attr('href') || '',
pubDate: ROCDate($('div p:nth-child(1)', e).text().replace('更新日期:', '').trim()),
category: [$('div p:nth-child(2)', e).text().replace('分類:', '')],
author: $('div p:nth-child(3)', e).text().replace('發布單位:', ''),
}));
return {
title: `陽明交大教務處公告 - ${name}`,
description: `國立陽明交大教務處公告 - ${name}`,
language: 'zh-TW',
link: url,
item,
};
}
export const route: Route = {
name: '教務處公告',
categories: ['university'],
maintainers: ['simbafs'],
description: `| 名稱 | :id |
| :----------------------: | :--: |
| 全部 | 2652 |
| 註冊組 | 2462 |
| 課務組 | 2502 |
| 綜合組 | 2523 |
| 實習組 | 2538 |
| 數位教學中心 | 2545 |
| 教學發展中心 | 2565 |
| 國際高教培訓暨認證中心 | 2617 |
| 雙語教育與學習推動辦公室 | 2638 |`,
path: '/aa/:id?',
parameters: { id: 'id, see below' },
example: '/nycu/aa/2652',
handler,
};
+61
View File
@@ -0,0 +1,61 @@
import { Data, Route } from '@/types';
import timezone from '@/utils/timezone';
import { CheerioAPI, load } from 'cheerio';
import { Context } from 'hono';
import ofetch from '@/utils/ofetch';
async function handler(ctx: Context): Promise<Data> {
const type = ctx.req.param('type') ?? '5';
const url = `https://infonews.nycu.edu.tw/index.php?SuperType=${type}&action=more&pagekey=1&categoryid=all`;
const $ = await ofetch<CheerioAPI>(url, {
parseResponse: load,
});
const typeName =
Object.fromEntries(
$('#masterMenu1 #option li a')
.toArray()
.slice(1, -1)
.map((a) => [new URLSearchParams(($(a).attr('href') || '').replace('index.php', '')).get('SuperType'), $(a).text().replaceAll(/\s+/g, '')])
)[type] || '未知分類';
const item = $('.category-style tr .style2')
.toArray()
.map((titleEle) => {
const date = $(titleEle).parent().next().find('td').text().split('-')[0]?.trim();
return {
title: $(titleEle).attr('title')?.trim() || '',
link: $(titleEle).find('a').attr('href') || '',
pubDate: date ? timezone(date, 8) : undefined,
};
});
return {
title: `陽明交大交大校園公告 - ${typeName}`,
description: `國立陽明交通大學校園公告 - ${typeName}`,
language: 'zh-TW',
link: url,
item,
};
}
export const route: Route = {
name: '校園公告',
categories: ['university'],
maintainers: ['simbafs'],
description: `| 名稱 | :type |
| :------: | :---: |
| 行政公告 | 5 |
| 演講課程 | 6 |
| 藝文體育 | 7 |
| 校園徵才 | 9 |
| 其他活動 | 8 |
| 電子公文 | 3 |
| 校外訊息 | 10 |`,
path: '/announcement/:type',
parameters: { type: '類型,見下表' },
example: '/nycu/announcement/5',
handler,
};
+54
View File
@@ -0,0 +1,54 @@
import { Data, Route } from '@/types';
import timezone from '@/utils/timezone';
import { CheerioAPI, load } from 'cheerio';
import { Context } from 'hono';
import ofetch from '@/utils/ofetch';
async function handler(ctx: Context): Promise<Data> {
const catagory = ctx.req.param('category') ?? 'all';
const url = `https://www.cs.nycu.edu.tw/announcements/${catagory === 'all' ? '' : catagory}`;
const $ = await ofetch<CheerioAPI>(url, {
parseResponse: load,
});
const item = $('.announcement-item')
.toArray()
.map((e) => ({
title: $('header a', e).text().trim(),
link: $('a', e).attr('href'),
pubDate: $('time', e).attr('datetime') ? timezone($('time', e).attr('datetime') || '', 8) : undefined,
}));
return {
title: `陽明交大資工系公告 - ${catagory}`,
description: `國立陽明交大資訊學院公告 - ${catagory}`,
language: 'zh-TW',
link: url,
item,
};
}
export const route: Route = {
name: '資訊學院公告',
categories: ['university'],
maintainers: ['simbafs'],
description: `| 名稱 | Name | :category |
| :--------: | :--------------: | :--------------: |
| 全部公告 | All | all |
| 獎學金 | Scholarships | scholarship |
| 課程/演講 | Courses | courses |
| 研究所 | Graduates | graduate |
| 學士班 | Undergraduates | undergraduate |
| 入學公告 | Admissions | candidate |
| 獲獎捷報 | Awards | awards |
| 系內徵才 | Internal Job | campus |
| 企業徵才 | Industry Job | corporation |
| 系計中 | Computer Center | cscc |
| 活動競賽 | activity | activity |
| 資訊人院刊 | NYC CCS MAGAZINE | NYC CCS MAGAZINE |`,
path: '/cs/:category?',
parameters: { category: 'categories, see below' },
example: '/nycu/cs/all',
handler,
};
+10
View File
@@ -0,0 +1,10 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'National Yang Ming Chiao Tung University',
url: 'nycu.edu.tw',
lang: 'zh-TW',
zh: {
name: '國立陽明交通大學',
},
};
+107
View File
@@ -0,0 +1,107 @@
import { Data, Route } from '@/types';
import timezone from '@/utils/timezone';
import { CheerioAPI, load } from 'cheerio';
import { Context } from 'hono';
import ofetch from '@/utils/ofetch';
function ROCDate(dateStr: string | Date): Date {
const date = new Date(dateStr);
date.setFullYear(date.getFullYear() + 1911);
return timezone(date, 8);
}
const data: Record<string, { module: string; name: string }> = {
'2660': {
module: 'nycu0091',
name: '榮譽榜 - 榮譽事蹟',
},
'2844': {
module: 'nycu0082',
name: '經濟支持及學生輔導 - 生輔一、二',
},
'3440': {
module: 'nycu0083',
name: '學生宿舍(陽明校區) - 住宿服務一',
},
'3465': {
module: 'nycu0084',
name: '學生宿舍(交大校區) - 住宿服務二',
},
'3494': {
module: 'nycu0085',
name: '課外活動 - 課外活動一、二組',
},
'3554': {
module: 'nycu0086',
name: '健康照護 - 衛生保健組',
},
'3594': {
module: 'nycu0087',
name: '職涯發展 - 職涯發展組',
},
'3635': {
module: 'nycu0088',
name: '服務學習 - 服務學習中心',
},
'3669': {
module: 'nycu0089',
name: '原民資源 - 原資中心',
},
'3681': {
module: 'nycu0090',
name: '深耕助學 - 深耕助學',
},
};
async function handler(ctx: Context): Promise<Data> {
const id = ctx.req.param('id') ?? '2844';
const { module, name } = data[id];
const url = `https://osa.nycu.edu.tw/osa/ch/app/data/list?module=${module}&id=${id}`;
const $ = await ofetch<CheerioAPI>(url, {
parseResponse: load,
});
const item = $('.newslist li')
.toArray()
.map((e) => ({
title: $('a', e).attr('title')?.trim() || '',
link: $('a', e).attr('href') || '',
pubDate: ROCDate($('div p:nth-child(1)', e).text().replace('更新日期:', '').trim() || ''),
category: [$('div p:nth-child(2)', e).text().replace('分類:', '')],
author: $('div p:nth-child(3)', e).text().replace('發布單位:', ''),
}));
return {
title: `陽明交大學務處公告 - ${name}`,
description: `國立陽明交大學務處公告 - ${name}`,
language: 'zh-TW',
link: url,
item,
};
}
export const route: Route = {
name: '學務處公告',
categories: ['university'],
maintainers: ['simbafs'],
description: `| 項目 | 組別 | :id |
| :----------------: | :--------------: | :--: |
| 經濟支持及學生輔導 | 生輔一、二組 | 2844 |
| 學生宿舍(陽明校區) | 住宿服務一組 | 3440 |
| 學生宿舍(交大校區) | 住宿服務二組 | 3465 |
| 課外活動 | 課外活動一、二組 | 3494 |
| 健康照護 | 衛生保健組 | 3554 |
| 職涯發展 | 職涯發展組 | 3594 |
| 服務學習 | 服務學習中心 | 3635 |
| 原民資源 | 原資中心 | 3669 |
| 深耕助學 | 深耕助學 | 3681 |
| 榮譽榜 | 榮譽事蹟 | 2660 |`,
path: '/osa/:id?',
parameters: { id: 'id, see below' },
example: '/nycu/osa/2844',
handler,
};