newsnow/shared/metadata.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-10-14 21:54:12 +08:00
import { sources } from "./sources"
import { typeSafeObjectEntries, typeSafeObjectFromEntries } from "./type.util"
import type { ColumnID, HiddenColumnID, Metadata, SourceID } from "./types"
2024-10-14 21:54:12 +08:00
export const columns = {
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
},
} as const
export const fixedColumnIds = ["focus", "hottest", "realtime"] as const satisfies Partial<ColumnID>[]
2024-11-03 00:59:44 +08:00
export const hiddenColumns = Object.keys(columns).filter(id => !fixedColumnIds.includes(id as any)) as HiddenColumnID[]
2024-10-14 21:54:12 +08:00
export const metadata: Metadata = typeSafeObjectFromEntries(typeSafeObjectEntries(columns).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
}]
}
}))