newsnow/shared/metadata.ts

59 lines
1.5 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 { Metadata } from "./types"
export const columnIds = ["focus", "realtime", "hottest", "china", "world", "tech", "finance"] as const
const originMetadata: Metadata = {
china: {
name: "国内",
2024-10-21 17:00:51 +08:00
sources: ["zhihu", "thepaper"],
2024-10-14 21:54:12 +08:00
},
world: {
name: "国际",
sources: ["zaobao", "cankaoxiaoxi"],
},
tech: {
name: "科技",
2024-10-20 20:28:49 +08:00
sources: ["ithome", "v2ex", "coolapk"],
2024-10-14 21:54:12 +08:00
},
finance: {
name: "财经",
2024-10-21 03:05:50 +08:00
sources: ["cls-telegraph", "cls-depth", "wallstreetcn", "wallstreetcn-hot", "wallstreetcn-news", "xueqiu-hotstock", "gelonghui"],
2024-10-14 21:54:12 +08:00
},
focus: {
name: "关注",
sources: [],
},
realtime: {
name: "实时",
sources: [],
},
hottest: {
name: "最热",
sources: [],
},
}
export const metadata = typeSafeObjectFromEntries(typeSafeObjectEntries(originMetadata).map(([k, v]) => {
switch (k) {
case "focus":
return [k, v]
case "hottest":
return [k, {
...v,
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.type === "hottest" && !v.redirect).map(([k]) => k),
}]
case "realtime":
return [k, {
...v,
2024-10-19 13:15:48 +08:00
sources: ["weibo", ...typeSafeObjectEntries(sources).filter(([, v]) => v.type === "realtime" && !v.redirect).map(([k]) => k)],
2024-10-14 21:54:12 +08:00
}]
default:
return [k, {
...v,
sources: v.sources.filter(s => sources[s]),
}]
}
}))