diff --git a/src/constants/univ.ts b/src/constants/univ.ts index d914fdf..3c813f2 100644 --- a/src/constants/univ.ts +++ b/src/constants/univ.ts @@ -1,7 +1,15 @@ -export type University = '가천대학교' | '서울시립대학교' -export const UNIVERITY_LINK_LIST = ['https://cyber.gachon.ac.kr', 'https://uclass.uos.ac.kr'] - -export const UNIVERITY_NAME_MAP: Record<(typeof UNIVERITY_LINK_LIST)[number], University> = { +export const UNIVERITY_NAME_MAP = { 'https://cyber.gachon.ac.kr': '가천대학교', 'https://uclass.uos.ac.kr': '서울시립대학교', -} + + /** + * @TODO 반영 예정인 대학교 목록 + * + * 'https://cn2.hongik.ac.kr': '홍익대학교', + */ +} as const + +export type UniversityLink = keyof typeof UNIVERITY_NAME_MAP +export type University = (typeof UNIVERITY_NAME_MAP)[UniversityLink] + +export const UNIVERITY_LINK_LIST = Object.keys(UNIVERITY_NAME_MAP) as UniversityLink[] diff --git a/src/services/index.ts b/src/services/index.ts index 9dcc0a2..09c645b 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,5 +1,6 @@ import * as cheerio from 'cheerio' +import type { University, UniversityLink } from '@/constants/univ' import { UNIVERITY_NAME_MAP } from '@/constants/univ' import type { Activity, Assignment, Course, Video } from '@/types' import { getLinkId, mapElement, getAttr, getText } from '@/utils' @@ -8,17 +9,20 @@ import type { AnyNode } from 'domhandler' type CheerioAPI = cheerio.CheerioAPI -const origin = window.location.origin +const origin = window.location.origin as UniversityLink const university = UNIVERITY_NAME_MAP[origin] -const univSpecific = { +const univSpecific: Record = { 가천대학교: { titleRegex: /\((\w{5}_\w{3})\)/, }, 서울시립대학교: { titleRegex: /\[(?:\w{5}_\w{2}|\w{2})]/, }, -}[university] + // 홍익대학교: { + // titleRegex: /\[\d+]$/, + // }, +} // 네트워크 요청을 담당하는 함수 export async function fetchHtml(url: string): Promise { @@ -51,7 +55,7 @@ function parseCourses($: CheerioAPI): Course[] { return mapElement($('.coursefullname'), (_, el) => { const $el = $(el) const id = getLinkId(getAttr($el, 'href')) - const title = getText($el).replace(univSpecific.titleRegex, '') + const title = getText($el).replace(univSpecific[university]?.titleRegex, '') return { id, title } }) }