Skip to content

Commit

Permalink
feat: 홍익대학교 추가(주석 처리)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangju2000 committed Oct 6, 2024
1 parent 29ed132 commit b84bfce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/constants/univ.ts
Original file line number Diff line number Diff line change
@@ -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[]
12 changes: 8 additions & 4 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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<University, { titleRegex: RegExp }> = {
가천대학교: {
titleRegex: /\((\w{5}_\w{3})\)/,
},
서울시립대학교: {
titleRegex: /\[(?:\w{5}_\w{2}|\w{2})]/,
},
}[university]
// 홍익대학교: {
// titleRegex: /\[\d+]$/,
// },
}

// 네트워크 요청을 담당하는 함수
export async function fetchHtml(url: string): Promise<string> {
Expand Down Expand Up @@ -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 }
})
}
Expand Down

0 comments on commit b84bfce

Please sign in to comment.