From b99a63259068dbec9d06b48e6ddc1be7c4642d3d Mon Sep 17 00:00:00 2001 From: Ou Date: Sun, 19 Jan 2025 18:44:48 +0800 Subject: [PATCH] feat: disable source only in CloudFlare --- package.json | 6 +- scripts/favicon.ts | 4 +- scripts/pinyin.ts | 13 -- scripts/refresh.ts | 2 +- scripts/source.ts | 27 +++ shared/pinyin.json | 7 +- shared/pre-sources.ts | 351 ++++++++++++++++++++++++++++++++++++++ shared/sources.json | 381 ++++++++++++++++++++++++++++++++++++++++++ shared/sources.ts | 342 +------------------------------------ shared/types.ts | 4 +- 10 files changed, 775 insertions(+), 362 deletions(-) delete mode 100644 scripts/pinyin.ts create mode 100644 scripts/source.ts create mode 100644 shared/pre-sources.ts create mode 100644 shared/sources.json diff --git a/package.json b/package.json index 7e230e0..4f43c51 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,10 @@ }, "homepage": "https://github.com/ourongxing/newsnow", "scripts": { - "dev": "vite dev", - "build": "vite build", + "dev": "npm run presource && vite dev", + "build": "npm run presource && vite build", "lint": "eslint", - "source": "tsx ./scripts/favicon.ts && tsx ./scripts/pinyin.ts", + "presource": "tsx ./scripts/favicon.ts && tsx ./scripts/source.ts", "start": "node --env-file .env.server dist/output/server/index.mjs", "preview": "cross-env CF_PAGES=1 npm run build && wrangler pages dev dist/output/public", "deploy": "cross-env CF_PAGES=1 npm run build && wrangler pages deploy dist/output/public", diff --git a/scripts/favicon.ts b/scripts/favicon.ts index 6911aa0..3097727 100644 --- a/scripts/favicon.ts +++ b/scripts/favicon.ts @@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url" import { join } from "node:path" import { Buffer } from "node:buffer" import { consola } from "consola" -import { originSources } from "../shared/sources" +import { originSources } from "../shared/pre-sources" const projectDir = fileURLToPath(new URL("..", import.meta.url)) const iconsDir = join(projectDir, "public", "icons") @@ -29,7 +29,7 @@ async function main() { try { const icon = join(iconsDir, `${id}.png`) if (fs.existsSync(icon)) { - consola.info(`${id}: icon exists. skip.`) + // consola.info(`${id}: icon exists. skip.`) return } if (!source.home) return diff --git a/scripts/pinyin.ts b/scripts/pinyin.ts deleted file mode 100644 index d24ccb6..0000000 --- a/scripts/pinyin.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { writeFileSync } from "node:fs" -import { join } from "node:path" -import { pinyin } from "@napi-rs/pinyin" -import { projectDir } from "../shared/dir" -import { sources } from "../shared/sources" - -const pinyinMap = Object.fromEntries(Object.entries(sources) - .filter(([, v]) => !v.redirect) - .map(([k, v]) => { - return [k, pinyin(v.title ? `${v.name}-${v.title}` : v.name).join("")] - })) - -writeFileSync(join(projectDir, "./shared/pinyin.json"), JSON.stringify(pinyinMap, undefined, 2)) diff --git a/scripts/refresh.ts b/scripts/refresh.ts index 54b9504..8e6c21f 100644 --- a/scripts/refresh.ts +++ b/scripts/refresh.ts @@ -1,4 +1,4 @@ -import { sources } from "../shared/sources" +import sources from "../shared/sources.json" Promise.all(Object.keys(sources).map(id => fetch(`https://newsnow.busiyi.world/api/s?id=${id}`), diff --git a/scripts/source.ts b/scripts/source.ts new file mode 100644 index 0000000..6010673 --- /dev/null +++ b/scripts/source.ts @@ -0,0 +1,27 @@ +import { writeFileSync } from "node:fs" +import { join } from "node:path" +import { pinyin } from "@napi-rs/pinyin" +import { consola } from "consola" +import { projectDir } from "../shared/dir" +import { genSources } from "../shared/pre-sources" + +const sources = genSources() +try { + const pinyinMap = Object.fromEntries(Object.entries(sources) + .filter(([, v]) => !v.redirect) + .map(([k, v]) => { + return [k, pinyin(v.title ? `${v.name}-${v.title}` : v.name).join("")] + })) + + writeFileSync(join(projectDir, "./shared/pinyin.json"), JSON.stringify(pinyinMap, undefined, 2)) + consola.info("Generated pinyin.json") +} catch { + consola.error("Failed to generate pinyin.json") +} + +try { + writeFileSync(join(projectDir, "./shared/sources.json"), JSON.stringify(Object.fromEntries(Object.entries(sources)), undefined, 2)) + consola.info("Generated sources.json") +} catch { + consola.error("Failed to generate sources.json") +} diff --git a/shared/pinyin.json b/shared/pinyin.json index 3c3c750..7bcb1d5 100644 --- a/shared/pinyin.json +++ b/shared/pinyin.json @@ -7,11 +7,13 @@ "wallstreetcn-quick": "huaerjiejianwen-shishikuaixun", "wallstreetcn-news": "huaerjiejianwen-zuixinzixun", "wallstreetcn-hot": "huaerjiejianwen-zuirewenzhang", + "36kr-quick": "36ke-kuaixun", "douyin": "douyin", "tieba": "baidutieba-reyi", "toutiao": "jinritoutiao", "ithome": "ITzhijia", "thepaper": "pengpaixinwen-rebang", + "sputniknewscn": "weixingtongxunshe", "cankaoxiaoxi": "cankaoxiaoxi", "cls-telegraph": "cailianshe-dianbao", "cls-depth": "cailianshe-shendu", @@ -25,9 +27,10 @@ "producthunt": "Product Hunt", "github-trending-today": "Github-Today", "bilibili-hot-search": "bilibili-resou", + "kuaishou": "kuaishou", "kaopu": "kaopuxinwen", "jin10": "jinshishuju", "baidu": "baiduresou", - "linuxdo-latest": "Linux DO-zuixin", - "linuxdo-hot": "Linux DO-remen" + "linuxdo-latest": "LINUX DO-zuixin", + "linuxdo-hot": "LINUX DO-jinrizuire" } diff --git a/shared/pre-sources.ts b/shared/pre-sources.ts new file mode 100644 index 0000000..d0554db --- /dev/null +++ b/shared/pre-sources.ts @@ -0,0 +1,351 @@ +import process from "node:process" +import { Interval } from "./consts" +import { typeSafeObjectFromEntries } from "./type.util" +import type { OriginSource, Source, SourceID } from "./types" + +const Time = { + Test: 1, + Realtime: 2 * 60 * 1000, + Fast: 5 * 60 * 1000, + Default: Interval, // 10min + Common: 30 * 60 * 1000, + Slow: 60 * 60 * 1000, +} + +export const originSources = { + "v2ex": { + name: "V2EX", + color: "slate", + home: "https://v2ex.com/", + sub: { + share: { + title: "最新分享", + column: "tech", + }, + }, + }, + "zhihu": { + name: "知乎", + type: "hottest", + column: "china", + color: "blue", + home: "https://www.zhihu.com", + }, + "weibo": { + name: "微博", + title: "实时热搜", + type: "hottest", + column: "china", + color: "red", + interval: Time.Realtime, + home: "https://weibo.com", + }, + "zaobao": { + name: "联合早报", + interval: Time.Common, + type: "realtime", + column: "world", + color: "red", + home: "https://www.zaobao.com", + }, + "coolapk": { + name: "酷安", + type: "hottest", + column: "tech", + color: "green", + title: "今日最热", + home: "https://coolapk.com", + }, + "wallstreetcn": { + name: "华尔街见闻", + color: "blue", + column: "finance", + home: "https://wallstreetcn.com/", + sub: { + quick: { + type: "realtime", + interval: Time.Fast, + title: "实时快讯", + }, + news: { + title: "最新资讯", + interval: Time.Common, + }, + hot: { + title: "最热文章", + type: "hottest", + interval: Time.Common, + }, + }, + }, + "36kr": { + name: "36氪", + type: "realtime", + color: "blue", + // cloudflare pages cannot access + disable: "cf", + home: "https://36kr.com", + column: "tech", + sub: { + quick: { + title: "快讯", + }, + }, + }, + "douyin": { + name: "抖音", + type: "hottest", + column: "china", + color: "gray", + home: "https://www.douyin.com", + }, + "hupu": { + name: "虎扑", + disable: true, + home: "https://hupu.com", + }, + "tieba": { + name: "百度贴吧", + title: "热议", + column: "china", + type: "hottest", + color: "blue", + home: "https://tieba.baidu.com", + }, + "toutiao": { + name: "今日头条", + type: "hottest", + column: "china", + color: "red", + home: "https://www.toutiao.com", + }, + "ithome": { + name: "IT之家", + color: "red", + column: "tech", + type: "realtime", + home: "https://www.ithome.com", + }, + "thepaper": { + name: "澎湃新闻", + interval: Time.Common, + type: "hottest", + column: "china", + title: "热榜", + color: "gray", + home: "https://www.thepaper.cn", + }, + "sputniknewscn": { + name: "卫星通讯社", + color: "orange", + // cloudflare pages cannot access + disable: "cf", + column: "world", + home: "https://sputniknews.cn", + }, + "cankaoxiaoxi": { + name: "参考消息", + color: "red", + column: "world", + interval: Time.Common, + home: "https://china.cankaoxiaoxi.com", + }, + "cls": { + name: "财联社", + color: "red", + column: "finance", + home: "https://www.cls.cn", + sub: { + telegraph: { + title: "电报", + interval: Time.Fast, + type: "realtime", + }, + depth: { + title: "深度", + }, + hot: { + title: "热门", + type: "hottest", + }, + }, + }, + "xueqiu": { + name: "雪球", + color: "blue", + home: "https://xueqiu.com", + column: "finance", + sub: { + hotstock: { + title: "热门股票", + interval: Time.Realtime, + type: "hottest", + }, + }, + }, + "gelonghui": { + name: "格隆汇", + color: "blue", + title: "事件", + column: "finance", + type: "realtime", + interval: Time.Realtime, + home: "https://www.gelonghui.com", + }, + "fastbull": { + name: "法布财经", + color: "emerald", + home: "https://www.fastbull.cn", + column: "finance", + sub: { + express: { + title: "快讯", + type: "realtime", + interval: Time.Realtime, + }, + news: { + title: "头条", + interval: Time.Common, + }, + }, + }, + "solidot": { + name: "Solidot", + color: "teal", + column: "tech", + home: "https://solidot.org", + interval: Time.Slow, + }, + "hackernews": { + name: "Hacker News", + color: "orange", + column: "tech", + type: "hottest", + home: "https://news.ycombinator.com/", + }, + "producthunt": { + name: "Product Hunt", + color: "red", + column: "tech", + type: "hottest", + home: "https://www.producthunt.com/", + }, + "github": { + name: "Github", + color: "gray", + home: "https://github.com/", + column: "tech", + sub: { + "trending-today": { + title: "Today", + type: "hottest", + }, + }, + }, + "bilibili": { + name: "哔哩哔哩", + color: "blue", + home: "https://www.bilibili.com", + sub: { + "hot-search": { + title: "热搜", + column: "china", + type: "hottest", + }, + }, + }, + "kuaishou": { + name: "快手", + type: "hottest", + column: "china", + color: "orange", + // cloudflare pages cannot access + disable: "cf", + home: "https://www.kuaishou.com", + }, + "kaopu": { + name: "靠谱新闻", + column: "world", + color: "gray", + interval: Time.Common, + desc: "不一定靠谱,多看多思考", + home: "https://kaopu.news/", + }, + "jin10": { + name: "金十数据", + column: "finance", + color: "blue", + type: "realtime", + home: "https://www.jin10.com", + }, + "baidu": { + name: "百度热搜", + column: "china", + color: "blue", + type: "hottest", + home: "https://www.baidu.com", + }, + "linuxdo": { + name: "LINUX DO", + column: "tech", + color: "slate", + home: "https://linux.do/", + disable: "cf", + sub: { + latest: { + title: "最新", + home: "https://linux.do/latest", + }, + hot: { + title: "今日最热", + type: "hottest", + interval: Time.Common, + home: "https://linux.do/hot", + }, + }, + }, +} as const satisfies Record + +export function genSources() { + const _: [SourceID, Source][] = [] + + Object.entries(originSources).forEach(([id, source]: [any, OriginSource]) => { + const parent = { + name: source.name, + type: source.type, + disable: source.disable, + desc: source.desc, + column: source.column, + home: source.home, + color: source.color ?? "primary", + interval: source.interval ?? Time.Default, + } + if (source.sub && Object.keys(source.sub).length) { + Object.entries(source.sub).forEach(([subId, subSource], i) => { + if (i === 0) { + _.push([id, { + redirect: `${id}-${subId}`, + ...parent, + ...subSource, + }] as [any, Source]) + } + _.push([`${id}-${subId}`, { ...parent, ...subSource }] as [any, Source]) + }) + } else { + _.push([id, { + title: source.title, + ...parent, + }]) + } + }) + + return typeSafeObjectFromEntries(_.filter(([_, v]) => { + if (v.disable === "cf" && process.env.CF_PAGES) { + return false + } else if (v.disable === true) { + return false + } else { + return true + } + })) +} diff --git a/shared/sources.json b/shared/sources.json new file mode 100644 index 0000000..2856f12 --- /dev/null +++ b/shared/sources.json @@ -0,0 +1,381 @@ +{ + "v2ex": { + "redirect": "v2ex-share", + "name": "V2EX", + "column": "tech", + "home": "https://v2ex.com/", + "color": "slate", + "interval": 600000, + "title": "最新分享" + }, + "v2ex-share": { + "name": "V2EX", + "column": "tech", + "home": "https://v2ex.com/", + "color": "slate", + "interval": 600000, + "title": "最新分享" + }, + "zhihu": { + "name": "知乎", + "type": "hottest", + "column": "china", + "home": "https://www.zhihu.com", + "color": "blue", + "interval": 600000 + }, + "weibo": { + "title": "实时热搜", + "name": "微博", + "type": "hottest", + "column": "china", + "home": "https://weibo.com", + "color": "red", + "interval": 120000 + }, + "zaobao": { + "name": "联合早报", + "type": "realtime", + "column": "world", + "home": "https://www.zaobao.com", + "color": "red", + "interval": 1800000 + }, + "coolapk": { + "title": "今日最热", + "name": "酷安", + "type": "hottest", + "column": "tech", + "home": "https://coolapk.com", + "color": "green", + "interval": 600000 + }, + "wallstreetcn": { + "redirect": "wallstreetcn-quick", + "name": "华尔街见闻", + "type": "realtime", + "column": "finance", + "home": "https://wallstreetcn.com/", + "color": "blue", + "interval": 300000, + "title": "实时快讯" + }, + "wallstreetcn-quick": { + "name": "华尔街见闻", + "type": "realtime", + "column": "finance", + "home": "https://wallstreetcn.com/", + "color": "blue", + "interval": 300000, + "title": "实时快讯" + }, + "wallstreetcn-news": { + "name": "华尔街见闻", + "column": "finance", + "home": "https://wallstreetcn.com/", + "color": "blue", + "interval": 1800000, + "title": "最新资讯" + }, + "wallstreetcn-hot": { + "name": "华尔街见闻", + "type": "hottest", + "column": "finance", + "home": "https://wallstreetcn.com/", + "color": "blue", + "interval": 1800000, + "title": "最热文章" + }, + "36kr": { + "redirect": "36kr-quick", + "name": "36氪", + "type": "realtime", + "disable": "cf", + "column": "tech", + "home": "https://36kr.com", + "color": "blue", + "interval": 600000, + "title": "快讯" + }, + "36kr-quick": { + "name": "36氪", + "type": "realtime", + "disable": "cf", + "column": "tech", + "home": "https://36kr.com", + "color": "blue", + "interval": 600000, + "title": "快讯" + }, + "douyin": { + "name": "抖音", + "type": "hottest", + "column": "china", + "home": "https://www.douyin.com", + "color": "gray", + "interval": 600000 + }, + "tieba": { + "title": "热议", + "name": "百度贴吧", + "type": "hottest", + "column": "china", + "home": "https://tieba.baidu.com", + "color": "blue", + "interval": 600000 + }, + "toutiao": { + "name": "今日头条", + "type": "hottest", + "column": "china", + "home": "https://www.toutiao.com", + "color": "red", + "interval": 600000 + }, + "ithome": { + "name": "IT之家", + "type": "realtime", + "column": "tech", + "home": "https://www.ithome.com", + "color": "red", + "interval": 600000 + }, + "thepaper": { + "title": "热榜", + "name": "澎湃新闻", + "type": "hottest", + "column": "china", + "home": "https://www.thepaper.cn", + "color": "gray", + "interval": 1800000 + }, + "sputniknewscn": { + "name": "卫星通讯社", + "disable": "cf", + "column": "world", + "home": "https://sputniknews.cn", + "color": "orange", + "interval": 600000 + }, + "cankaoxiaoxi": { + "name": "参考消息", + "column": "world", + "home": "https://china.cankaoxiaoxi.com", + "color": "red", + "interval": 1800000 + }, + "cls": { + "redirect": "cls-telegraph", + "name": "财联社", + "type": "realtime", + "column": "finance", + "home": "https://www.cls.cn", + "color": "red", + "interval": 300000, + "title": "电报" + }, + "cls-telegraph": { + "name": "财联社", + "type": "realtime", + "column": "finance", + "home": "https://www.cls.cn", + "color": "red", + "interval": 300000, + "title": "电报" + }, + "cls-depth": { + "name": "财联社", + "column": "finance", + "home": "https://www.cls.cn", + "color": "red", + "interval": 600000, + "title": "深度" + }, + "cls-hot": { + "name": "财联社", + "type": "hottest", + "column": "finance", + "home": "https://www.cls.cn", + "color": "red", + "interval": 600000, + "title": "热门" + }, + "xueqiu": { + "redirect": "xueqiu-hotstock", + "name": "雪球", + "type": "hottest", + "column": "finance", + "home": "https://xueqiu.com", + "color": "blue", + "interval": 120000, + "title": "热门股票" + }, + "xueqiu-hotstock": { + "name": "雪球", + "type": "hottest", + "column": "finance", + "home": "https://xueqiu.com", + "color": "blue", + "interval": 120000, + "title": "热门股票" + }, + "gelonghui": { + "title": "事件", + "name": "格隆汇", + "type": "realtime", + "column": "finance", + "home": "https://www.gelonghui.com", + "color": "blue", + "interval": 120000 + }, + "fastbull": { + "redirect": "fastbull-express", + "name": "法布财经", + "type": "realtime", + "column": "finance", + "home": "https://www.fastbull.cn", + "color": "emerald", + "interval": 120000, + "title": "快讯" + }, + "fastbull-express": { + "name": "法布财经", + "type": "realtime", + "column": "finance", + "home": "https://www.fastbull.cn", + "color": "emerald", + "interval": 120000, + "title": "快讯" + }, + "fastbull-news": { + "name": "法布财经", + "column": "finance", + "home": "https://www.fastbull.cn", + "color": "emerald", + "interval": 1800000, + "title": "头条" + }, + "solidot": { + "name": "Solidot", + "column": "tech", + "home": "https://solidot.org", + "color": "teal", + "interval": 3600000 + }, + "hackernews": { + "name": "Hacker News", + "type": "hottest", + "column": "tech", + "home": "https://news.ycombinator.com/", + "color": "orange", + "interval": 600000 + }, + "producthunt": { + "name": "Product Hunt", + "type": "hottest", + "column": "tech", + "home": "https://www.producthunt.com/", + "color": "red", + "interval": 600000 + }, + "github": { + "redirect": "github-trending-today", + "name": "Github", + "type": "hottest", + "column": "tech", + "home": "https://github.com/", + "color": "gray", + "interval": 600000, + "title": "Today" + }, + "github-trending-today": { + "name": "Github", + "type": "hottest", + "column": "tech", + "home": "https://github.com/", + "color": "gray", + "interval": 600000, + "title": "Today" + }, + "bilibili": { + "redirect": "bilibili-hot-search", + "name": "哔哩哔哩", + "type": "hottest", + "column": "china", + "home": "https://www.bilibili.com", + "color": "blue", + "interval": 600000, + "title": "热搜" + }, + "bilibili-hot-search": { + "name": "哔哩哔哩", + "type": "hottest", + "column": "china", + "home": "https://www.bilibili.com", + "color": "blue", + "interval": 600000, + "title": "热搜" + }, + "kuaishou": { + "name": "快手", + "type": "hottest", + "disable": "cf", + "column": "china", + "home": "https://www.kuaishou.com", + "color": "orange", + "interval": 600000 + }, + "kaopu": { + "name": "靠谱新闻", + "desc": "不一定靠谱,多看多思考", + "column": "world", + "home": "https://kaopu.news/", + "color": "gray", + "interval": 1800000 + }, + "jin10": { + "name": "金十数据", + "type": "realtime", + "column": "finance", + "home": "https://www.jin10.com", + "color": "blue", + "interval": 600000 + }, + "baidu": { + "name": "百度热搜", + "type": "hottest", + "column": "china", + "home": "https://www.baidu.com", + "color": "blue", + "interval": 600000 + }, + "linuxdo": { + "redirect": "linuxdo-latest", + "name": "LINUX DO", + "disable": "cf", + "column": "tech", + "home": "https://linux.do/latest", + "color": "slate", + "interval": 600000, + "title": "最新" + }, + "linuxdo-latest": { + "name": "LINUX DO", + "disable": "cf", + "column": "tech", + "home": "https://linux.do/latest", + "color": "slate", + "interval": 600000, + "title": "最新" + }, + "linuxdo-hot": { + "name": "LINUX DO", + "type": "hottest", + "disable": "cf", + "column": "tech", + "home": "https://linux.do/hot", + "color": "slate", + "interval": 1800000, + "title": "今日最热" + } +} diff --git a/shared/sources.ts b/shared/sources.ts index ea8b6f9..b22cb50 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -1,340 +1,4 @@ -import { Interval } from "./consts" -import { typeSafeObjectFromEntries } from "./type.util" -import type { OriginSource, Source, SourceID } from "./types" +import _sources from "./sources.json" -const Time = { - Test: 1, - Realtime: 2 * 60 * 1000, - Fast: 5 * 60 * 1000, - Default: Interval, // 10min - Common: 30 * 60 * 1000, - Slow: 60 * 60 * 1000, -} - -export const originSources = { - "v2ex": { - name: "V2EX", - color: "slate", - home: "https://v2ex.com/", - sub: { - share: { - title: "最新分享", - column: "tech", - }, - }, - }, - "zhihu": { - name: "知乎", - type: "hottest", - column: "china", - color: "blue", - home: "https://www.zhihu.com", - }, - "weibo": { - name: "微博", - title: "实时热搜", - type: "hottest", - column: "china", - color: "red", - interval: Time.Realtime, - home: "https://weibo.com", - }, - "zaobao": { - name: "联合早报", - interval: Time.Common, - type: "realtime", - column: "world", - color: "red", - home: "https://www.zaobao.com", - }, - "coolapk": { - name: "酷安", - type: "hottest", - column: "tech", - color: "green", - title: "今日最热", - home: "https://coolapk.com", - }, - "wallstreetcn": { - name: "华尔街见闻", - color: "blue", - column: "finance", - home: "https://wallstreetcn.com/", - sub: { - quick: { - type: "realtime", - interval: Time.Fast, - title: "实时快讯", - }, - news: { - title: "最新资讯", - interval: Time.Common, - }, - hot: { - title: "最热文章", - type: "hottest", - interval: Time.Common, - }, - }, - }, - "36kr": { - name: "36氪", - type: "realtime", - color: "blue", - // cloudflare pages cannot access - disable: true, - home: "https://36kr.com", - sub: { - quick: { - title: "快讯", - }, - }, - }, - "douyin": { - name: "抖音", - type: "hottest", - column: "china", - color: "gray", - home: "https://www.douyin.com", - }, - "hupu": { - name: "虎扑", - disable: true, - home: "https://hupu.com", - }, - "tieba": { - name: "百度贴吧", - title: "热议", - column: "china", - type: "hottest", - color: "blue", - home: "https://tieba.baidu.com", - }, - "toutiao": { - name: "今日头条", - type: "hottest", - column: "china", - color: "red", - home: "https://www.toutiao.com", - }, - "ithome": { - name: "IT之家", - color: "red", - column: "tech", - type: "realtime", - home: "https://www.ithome.com", - }, - "thepaper": { - name: "澎湃新闻", - interval: Time.Common, - type: "hottest", - column: "china", - title: "热榜", - color: "gray", - home: "https://www.thepaper.cn", - }, - "sputniknewscn": { - name: "卫星通讯社", - color: "orange", - // cloudflare pages cannot access - disable: true, - home: "https://sputniknews.cn", - }, - "cankaoxiaoxi": { - name: "参考消息", - color: "red", - column: "world", - interval: Time.Common, - home: "https://china.cankaoxiaoxi.com", - }, - "cls": { - name: "财联社", - color: "red", - column: "finance", - home: "https://www.cls.cn", - sub: { - telegraph: { - title: "电报", - interval: Time.Fast, - type: "realtime", - }, - depth: { - title: "深度", - }, - hot: { - title: "热门", - type: "hottest", - }, - }, - }, - "xueqiu": { - name: "雪球", - color: "blue", - home: "https://xueqiu.com", - column: "finance", - sub: { - hotstock: { - title: "热门股票", - interval: Time.Realtime, - type: "hottest", - }, - }, - }, - "gelonghui": { - name: "格隆汇", - color: "blue", - title: "事件", - column: "finance", - type: "realtime", - interval: Time.Realtime, - home: "https://www.gelonghui.com", - }, - "fastbull": { - name: "法布财经", - color: "emerald", - home: "https://www.fastbull.cn", - column: "finance", - sub: { - express: { - title: "快讯", - type: "realtime", - interval: Time.Realtime, - }, - news: { - title: "头条", - interval: Time.Common, - }, - }, - }, - "solidot": { - name: "Solidot", - color: "teal", - column: "tech", - home: "https://solidot.org", - interval: Time.Slow, - }, - "hackernews": { - name: "Hacker News", - color: "orange", - column: "tech", - type: "hottest", - home: "https://news.ycombinator.com/", - }, - "producthunt": { - name: "Product Hunt", - color: "red", - column: "tech", - type: "hottest", - home: "https://www.producthunt.com/", - }, - "github": { - name: "Github", - color: "gray", - home: "https://github.com/", - column: "tech", - sub: { - "trending-today": { - title: "Today", - type: "hottest", - }, - }, - }, - "bilibili": { - name: "哔哩哔哩", - color: "blue", - home: "https://www.bilibili.com", - sub: { - "hot-search": { - title: "热搜", - column: "china", - type: "hottest", - }, - }, - }, - "kuaishou": { - name: "快手", - type: "hottest", - column: "china", - color: "orange", - // cloudflare pages cannot access - disable: true, - home: "https://www.kuaishou.com", - }, - "kaopu": { - name: "靠谱新闻", - column: "world", - color: "gray", - interval: Time.Common, - desc: "不一定靠谱,多看多思考", - home: "https://kaopu.news/", - }, - "jin10": { - name: "金十数据", - column: "finance", - color: "blue", - type: "realtime", - home: "https://www.jin10.com", - }, - "baidu": { - name: "百度热搜", - column: "china", - color: "blue", - type: "hottest", - home: "https://www.baidu.com", - }, - "linuxdo": { - name: "LINUX DO", - column: "tech", - color: "slate", - home: "https://linux.do/", - sub: { - latest: { - title: "最新", - home: "https://linux.do/latest", - }, - hot: { - title: "今日最热", - type: "hottest", - interval: Time.Common, - home: "https://linux.do/hot", - }, - }, - }, -} as const satisfies Record - -export const sources = genSources() -function genSources() { - const _: [SourceID, Source][] = [] - - Object.entries(originSources).forEach(([id, source]: [any, OriginSource]) => { - const parent = { - name: source.name, - type: source.type, - disable: source.disable, - desc: source.desc, - column: source.column, - home: source.home, - color: source.color ?? "primary", - interval: source.interval ?? Time.Default, - } - if (source.sub && Object.keys(source.sub).length) { - Object.entries(source.sub).forEach(([subId, subSource], i) => { - if (i === 0) { - _.push([id, { - redirect: `${id}-${subId}`, - ...parent, - ...subSource, - }] as [any, Source]) - } - _.push([`${id}-${subId}`, { ...parent, ...subSource }] as [any, Source]) - }) - } else { - _.push([id, { - title: source.title, - ...parent, - }]) - } - }) - - return typeSafeObjectFromEntries(_.filter(([_, v]) => !v.disable)) -} +export const sources = _sources as Record +export default sources diff --git a/shared/types.ts b/shared/types.ts index 40cd743..5d0e8f1 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -1,6 +1,6 @@ import type { colors } from "unocss/preset-mini" import type { columns, fixedColumnIds } from "./metadata" -import type { originSources } from "./sources" +import type { originSources } from "./pre-sources" export type Color = "primary" | Exclude @@ -75,7 +75,7 @@ export interface Source { /** * @default false */ - disable?: boolean + disable?: boolean | "cf" redirect?: SourceID }