Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions app/composables/useSessionFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { SessionSummary } from '#shared/types/session'
import { TAG_NAMES } from '#shared/utils/session'

export interface FilterOption {
id: string
Expand Down Expand Up @@ -32,21 +33,14 @@ export function useSessionFilter({ sessionsByDay, selectedDay, locale }: UseSess
return isZh.value ? zh || en : en || zh
}

const DIFFICULTY_LABELS: Record<string, { zh: string, en: string }> = {
Elementary: { zh: '入門', en: 'Beginner' },
Intermediate: { zh: '中階', en: 'Intermediate' },
Advanced: { zh: '進階', en: 'Advanced' },
Professional: { zh: '專業', en: 'Professional' },
}

// The session type is offered as a filterable tag alongside its real tags.
function sessionTags(session: SessionSummary): FilterOption[] {
const lang = toValue(locale)
return [
{ id: `type:${session.zh.type}\u0000${session.en.type}`, label: session[lang].type },
...session.tags.map((tag) => ({
id: `tag:${tag}`,
label: DIFFICULTY_LABELS[tag]?.[lang] ?? tag,
label: TAG_NAMES[tag]?.[lang] ?? tag,
})),
].filter((tag) => tag.label)
}
Expand Down
16 changes: 2 additions & 14 deletions server/utils/opass/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseDifficulty } from '#server/utils/pretalx/parser'
import { TAG_NAMES } from '#shared/utils/session'

// OPass app 的 tag 分類沿用 2025:議程以 slug id 參照 tag,
// 而頂層 `tags` 字典提供每個 slug 的多語名稱。分類僅含語言與難度,
Expand Down Expand Up @@ -29,21 +30,8 @@ const LANGUAGE_GENERALIZE_MAP: Record<string, string> = {
その他: 'others',
}

// 各通用鍵(語言 + 難度)的多語顯示名稱(沿用 2025 tagTranslations)。
const TAG_NAMES: Record<string, { zh: string, en: string }> = {
'zh-tw': { zh: '漢語', en: 'Mandarin' },
'en': { zh: '英語', en: 'English' },
'ja-JP': { zh: '日本語', en: '日本語' },
'taiwanese': { zh: '台語', en: '台語' },
'others': { zh: '其他', en: '其他' },
'Elementary': { zh: '入門', en: 'Elementary' },
'Intermediate': { zh: '中階', en: 'Intermediate' },
'Advanced': { zh: '進階', en: 'Advanced' },
'Professional': { zh: '專業', en: 'Professional' },
}

function buildTag(id: string, key: string): OpassTag {
const name = TAG_NAMES[key]!
const name = TAG_NAMES[key] ?? { zh: key, en: key }
return { id, zh: { name: name.zh }, en: { name: name.en } }
Comment thread
mirumodapon marked this conversation as resolved.
}

Expand Down
32 changes: 29 additions & 3 deletions server/utils/pretalx/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ export function parseTrack(trackId: Submission['track'], pretalxData: PretalxRes
}

// 解析議程標籤,並把正規化後的難度(若有)一併併入標籤清單,
// 讓難度成為標籤的一部分而非獨立欄位
export function parseTags(tagIds: Submission['tags'], pretalxData: PretalxResult, difficulty?: SessionDifficulty): string[] {
// 將 appends(難度、語言等)前置於 Pretalx 公開標籤之前
export function parseTags(tagIds: Submission['tags'], pretalxData: PretalxResult, appends: string[] = []): string[] {
const tagMap = pretalxData.tags.map

Comment thread
mirumodapon marked this conversation as resolved.
const tags = tagIds
.map((tagId) => tagMap[tagId])
.filter((tag): tag is Tag => tag !== undefined && tag.is_public)
.map((tag) => tag.tag)

return difficulty ? [difficulty, ...tags] : tags
return [...appends, ...tags]
}

// 將投稿者填寫的難度原始字串正規化成統一的英文 enum,無法對應時回傳 undefined。
Expand All @@ -157,3 +157,29 @@ export function parseDifficulty(difficulty: string | undefined): SessionDifficul

return DIFFICULTY_GENERALIZE_MAP[difficulty.trim()]
}

export function parseLanguage(language: string | undefined): string | undefined {
if (!language) {
return undefined
}

const lang = language.trim().toLowerCase()

if (lang === 'english' || lang === '英文' || lang === '英語') {
return 'English'
}

if (lang === '中文' || lang === 'mandarin') {
return 'Mandarin'
}

if (lang === 'japanese' || lang === '日文' || lang === '日語') {
return 'Japanese'
}

if (lang === 'chinese' || lang === '中国語') {
return 'Chinese'
}

return 'others'
Comment thread
mirumodapon marked this conversation as resolved.
}
10 changes: 7 additions & 3 deletions server/utils/pretalx/sessions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PretalxResult, Submission } from '#shared/types/pretalx'
import type { SessionSummary } from '#shared/types/session'
import { parseAnswer, parseDifficulty, parseSlot, parseSpeaker, parseTags, parseTrack, parseType } from './parser'
import { parseAnswer, parseDifficulty, parseLanguage, parseSlot, parseSpeaker, parseTags, parseTrack, parseType } from './parser'

// 將單一 pretalx submission 轉換成 SessionSummary。
// 若 submission 沒有有效的時段(slot/start/end/room),回傳 null。
Expand All @@ -13,6 +13,10 @@ export function buildSessionSummary(submission: Submission, data: PretalxResult)
const slot = parseSlot(submission.slots[0], data)
const speakers = parseSpeaker(submission.speakers, data)
const type = parseType(submission.submission_type, data)
const difficulty = parseDifficulty(answers.difficulty)
const language = parseLanguage(answers.language) || ''

const appendedTags = [difficulty, language].filter(Boolean) as string[]

if (!slot || !slot.start || !slot.end || !slot.room) {
return null
Expand All @@ -23,7 +27,7 @@ export function buildSessionSummary(submission: Submission, data: PretalxResult)
room: slot.room.name,
start: slot.start,
end: slot.end,
language: answers.language,
language,
track: parseTrack(submission.track, data),
speakers,
zh: {
Expand All @@ -36,7 +40,7 @@ export function buildSessionSummary(submission: Submission, data: PretalxResult)
describe: answers.enDesc || submission.abstract,
type: type.name.en || type.name['zh-hant'],
},
tags: parseTags(submission.tags, data, parseDifficulty(answers.difficulty)),
tags: parseTags(submission.tags, data, appendedTags),
uri: `https://coscup.org/2026/session/${submission.code}`,
}
}
Expand Down
16 changes: 16 additions & 0 deletions shared/utils/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 各通用鍵(語言 + 難度)的多語顯示名稱(沿用 2025 tagTranslations)。
export const TAG_NAMES: Record<string, { zh: string, en: string }> = {
'zh-tw': { zh: '漢語', en: 'Mandarin' },
'en': { zh: '英語', en: 'English' },
'ja-JP': { zh: '日本語', en: 'Japanese' },
'others': { zh: '其他', en: 'Others' },
'Elementary': { zh: '入門', en: 'Elementary' },
'Intermediate': { zh: '中階', en: 'Intermediate' },
'Advanced': { zh: '進階', en: 'Advanced' },
'Professional': { zh: '專業', en: 'Professional' },
'Chinese': { zh: '中國語', en: 'Chinese' },
'English': { zh: '英語', en: 'English' },
'Japanese': { zh: '日本語', en: 'Japanese' },
'Mandarin': { zh: '中文', en: 'Mandarin' },
'Taiwanese': { zh: '台語', en: 'Taiwanese' },
}