newsnow/shared/metadata.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

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