newsnow/shared/metadata.ts
2024-10-26 00:00:33 +08:00

55 lines
1.3 KiB
TypeScript

import { sources } from "./sources"
import { typeSafeObjectEntries, typeSafeObjectFromEntries } from "./type.util"
import type { ColumnID, Metadata, SourceID } from "./types"
export const columnIds = ["focus", "realtime", "hottest", "china", "world", "tech", "finance"] as const
const columnName: Record<ColumnID, { zh: string }> = {
china: {
zh: "国内",
},
world: {
zh: "国际",
},
tech: {
zh: "科技",
},
finance: {
zh: "财经",
},
focus: {
zh: "关注",
},
realtime: {
zh: "实时",
},
hottest: {
zh: "最热",
},
}
export const metadata: Metadata = typeSafeObjectFromEntries(typeSafeObjectEntries(columnName).map(([k, v]) => {
switch (k) {
case "focus":
return [k, {
name: v.zh,
sources: [] as SourceID[],
}]
case "hottest":
return [k, {
name: v.zh,
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.type === "hottest" && !v.redirect).map(([k]) => k),
}]
case "realtime":
return [k, {
name: v.zh,
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.type === "realtime" && !v.redirect).map(([k]) => k),
}]
default:
return [k, {
name: v.zh,
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.column === k && !v.redirect).map(([k]) => k),
}]
}
}))