newsnow/shared/sources.ts

115 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-10-08 20:49:19 +08:00
import { typeSafeObjectFromEntries } from "./type.util"
import type { OriginSource, Source, SourceID } from "./types"
2024-10-09 02:53:38 +08:00
const Time = {
2024-10-09 15:50:14 +08:00
test: 1,
2024-10-09 02:53:38 +08:00
half: 30 * 60 * 1000,
five: 5 * 60 * 1000,
}
2024-10-08 20:49:19 +08:00
export const originSources = {
"v2ex": {
name: "V2EX",
home: "https://v2ex.com/",
},
2024-10-09 02:53:38 +08:00
"coolapk": {
name: "酷安",
home: "https://coolapk.com",
},
2024-10-08 20:49:19 +08:00
"wallstreetcn": {
name: "华尔街见闻",
home: "https://wallstreetcn.com/",
title: "快讯",
},
"sputniknewscn": {
name: "俄罗斯卫星通讯社",
home: "https://sputniknews.cn",
},
2024-10-09 02:53:38 +08:00
"cankaoxiaoxi": {
name: "参考消息",
interval: Time.half,
home: "https://china.cankaoxiaoxi.com",
},
2024-10-08 20:49:19 +08:00
"36kr": {
name: "36氪",
home: "https://36kr.com",
sub: {
quick: {
title: "快讯",
},
},
},
"douyin": {
name: "抖音",
home: "https://www.douyin.com",
},
"hupu": {
name: "虎扑",
home: "https://hupu.com",
},
"zhihu": {
name: "知乎",
home: "https://www.zhihu.com",
},
"weibo": {
name: "微博",
title: "实时热搜",
interval: 5 * 60 * 1000,
home: "https://weibo.com",
},
"tieba": {
name: "百度贴吧",
home: "https://tieba.baidu.com",
},
"zaobao": {
name: "联合早报",
home: "https://www.zaobao.com",
},
"thepaper": {
name: "澎湃新闻",
2024-10-09 02:53:38 +08:00
interval: Time.half,
2024-10-08 20:49:19 +08:00
home: "https://www.thepaper.cn",
},
"toutiao": {
name: "今日头条",
home: "https://www.toutiao.com",
},
"ithome": {
name: "IT之家",
home: "https://www.ithome.com",
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()
function genSources() {
const _: [SourceID, Source][] = []
Object.entries(originSources).forEach(([id, source]: [any, OriginSource]) => {
if (source.sub && Object.keys(source.sub).length) {
Object.entries(source.sub).forEach(([subId, subSource], i) => {
if (i === 0) {
_.push([id, {
redirect: `${id}-${subId}`,
name: source.name,
interval: source.interval,
...subSource,
}] as [any, Source])
}
_.push([`${id}-${subId}`, {
name: source.name,
interval: source.interval,
...subSource,
}] as [any, Source])
})
} else {
_.push([id, {
name: source.name,
interval: source.interval,
title: source.title,
}])
}
})
return typeSafeObjectFromEntries(_)
}