Files
o2o-weather/admin/src/cards/topics.ts
T

21 lines
897 B
TypeScript

import spec from '../../topics.json'
/** 날씨 타로 주제(대주제 > 소주제). 대주제마다 꾸밈(skin)·기본 색·먼저 고를 아이콘이 정해져 있다 (topics.json) */
export type Category = (typeof spec.categories)[number]
export const CATEGORIES: Category[] = spec.categories
/** '이별', '연애 이별', '연애' 처럼 들어온 주제에서 대주제를 찾는다 */
export function categoryOf(topic: string) {
const t = topic.trim()
return CATEGORIES.find((c) => t.includes(c.name) || c.subtopics.some((s) => t.includes(s)))
}
/** 그 주제의 타로 질문 (소주제 질문, 없으면 대주제 질문) */
export function questionOf(topic: string) {
const c = categoryOf(topic)
if (!c) return ''
const sub = c.subtopics.find((x) => topic.includes(x))
const q = c.questions as Record<string, string | undefined>
return q[sub ?? ''] ?? q[''] ?? ''
}