newsnow/shared/sources.ts

207 lines
4.3 KiB
TypeScript
Raw Normal View History

2024-10-10 22:47:25 +08:00
import { Interval } from "./consts"
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-10 22:47:25 +08:00
Test: 1,
Realtime: 2 * 60 * 1000,
Fast: 5 * 60 * 1000,
Default: Interval, // 10min
Common: 30 * 60 * 1000,
Slow: 60 * 60 * 1000,
2024-10-09 02:53:38 +08:00
}
2024-10-08 20:49:19 +08:00
export const originSources = {
"v2ex": {
name: "V2EX",
2024-10-12 12:49:20 +08:00
color: "slate",
2024-10-08 20:49:19 +08:00
home: "https://v2ex.com/",
2024-10-20 20:28:49 +08:00
sub: {
share: {
title: "最新分享",
},
},
2024-10-08 20:49:19 +08:00
},
2024-10-14 21:54:12 +08:00
"zhihu": {
name: "知乎",
type: "hottest",
color: "blue",
2024-10-14 21:54:12 +08:00
home: "https://www.zhihu.com",
},
"weibo": {
name: "微博",
title: "实时热搜",
type: "hottest",
color: "red",
interval: Time.Realtime,
home: "https://weibo.com",
},
"zaobao": {
name: "联合早报",
interval: Time.Common,
2024-10-19 13:15:48 +08:00
type: "realtime",
2024-10-14 21:54:12 +08:00
color: "red",
home: "https://www.zaobao.com",
},
2024-10-09 02:53:38 +08:00
"coolapk": {
name: "酷安",
2024-10-11 23:44:50 +08:00
type: "hottest",
2024-10-12 12:49:20 +08:00
color: "green",
2024-10-12 15:50:44 +08:00
title: "今日最热",
2024-10-09 02:53:38 +08:00
home: "https://coolapk.com",
},
2024-10-08 20:49:19 +08:00
"wallstreetcn": {
name: "华尔街见闻",
color: "blue",
2024-10-08 20:49:19 +08:00
home: "https://wallstreetcn.com/",
2024-10-21 01:38:58 +08:00
sub: {
quick: {
type: "realtime",
interval: Time.Fast,
title: "实时快讯",
},
news: {
title: "最新资讯",
interval: Time.Common,
},
hot: {
title: "最热文章",
type: "hottest",
interval: Time.Common,
},
},
2024-10-08 20:49:19 +08:00
},
"36kr": {
name: "36氪",
2024-10-14 21:54:12 +08:00
type: "realtime",
color: "blue",
2024-10-21 01:38:58 +08:00
disable: true,
2024-10-08 20:49:19 +08:00
home: "https://36kr.com",
sub: {
quick: {
title: "快讯",
},
},
},
"douyin": {
name: "抖音",
2024-10-11 23:44:50 +08:00
type: "hottest",
2024-10-12 12:49:20 +08:00
color: "gray",
2024-10-08 20:49:19 +08:00
home: "https://www.douyin.com",
},
"hupu": {
name: "虎扑",
2024-10-17 15:33:33 +08:00
disable: true,
2024-10-08 20:49:19 +08:00
home: "https://hupu.com",
},
"tieba": {
name: "百度贴吧",
2024-10-21 17:00:51 +08:00
title: "热议",
type: "hottest",
color: "blue",
2024-10-08 20:49:19 +08:00
home: "https://tieba.baidu.com",
},
"toutiao": {
name: "今日头条",
2024-10-11 23:44:50 +08:00
type: "hottest",
2024-10-12 12:49:20 +08:00
color: "red",
2024-10-08 20:49:19 +08:00
home: "https://www.toutiao.com",
},
"ithome": {
name: "IT之家",
2024-10-12 12:49:20 +08:00
color: "red",
2024-10-14 21:54:12 +08:00
type: "realtime",
2024-10-08 20:49:19 +08:00
home: "https://www.ithome.com",
},
2024-10-14 21:54:12 +08:00
"thepaper": {
name: "澎湃新闻",
interval: Time.Common,
2024-10-21 17:00:51 +08:00
type: "hottest",
title: "热榜",
color: "gray",
2024-10-14 21:54:12 +08:00
home: "https://www.thepaper.cn",
},
"sputniknewscn": {
name: "卫星通讯社",
color: "orange",
2024-10-17 15:33:33 +08:00
disable: true,
2024-10-14 21:54:12 +08:00
home: "https://sputniknews.cn",
},
"cankaoxiaoxi": {
name: "参考消息",
color: "red",
interval: Time.Common,
home: "https://china.cankaoxiaoxi.com",
},
2024-10-21 01:38:58 +08:00
"cls": {
name: "财联社",
color: "red",
home: "https://www.cls.cn",
sub: {
telegraph: {
title: "电报",
interval: Time.Fast,
type: "realtime",
},
depth: {
title: "深度头条",
interval: Time.Common,
},
},
},
2024-10-21 02:18:36 +08:00
"xueqiu": {
name: "雪球",
color: "blue",
home: "https://xueqiu.com",
sub: {
hotstock: {
title: "热门股票",
interval: Time.Realtime,
type: "hottest",
},
},
},
2024-10-21 03:05:50 +08:00
"gelonghui": {
name: "格隆汇",
color: "blue",
title: "事件",
type: "realtime",
2024-10-21 03:05:50 +08:00
interval: Time.Realtime,
home: "https://www.gelonghui.com",
},
2024-10-08 20:49:19 +08:00
} as const satisfies Record<string, OriginSource>
export const sources = genSources()
function genSources() {
const _: [SourceID, Source][] = []
Object.entries(originSources).forEach(([id, source]: [any, OriginSource]) => {
2024-10-14 21:54:12 +08:00
const parent = {
name: source.name,
type: source.type,
2024-10-17 15:33:33 +08:00
disable: source.disable,
2024-10-14 21:54:12 +08:00
color: source.color ?? "red",
interval: source.interval ?? Time.Default,
}
2024-10-08 20:49:19 +08:00
if (source.sub && Object.keys(source.sub).length) {
Object.entries(source.sub).forEach(([subId, subSource], i) => {
if (i === 0) {
_.push([id, {
redirect: `${id}-${subId}`,
2024-10-14 21:54:12 +08:00
...parent,
2024-10-08 20:49:19 +08:00
...subSource,
}] as [any, Source])
}
2024-10-14 21:54:12 +08:00
_.push([`${id}-${subId}`, { ...parent, ...subSource }] as [any, Source])
2024-10-08 20:49:19 +08:00
})
} else {
_.push([id, {
title: source.title,
2024-10-14 21:54:12 +08:00
...parent,
2024-10-08 20:49:19 +08:00
}])
}
})
2024-10-17 15:33:33 +08:00
return typeSafeObjectFromEntries(_.filter(([_, v]) => !v.disable))
2024-10-08 20:49:19 +08:00
}