diff --git a/public/icons/wallstreetcn.png b/public/icons/wallstreetcn.png new file mode 100644 index 0000000..01f0509 Binary files /dev/null and b/public/icons/wallstreetcn.png differ diff --git a/server/sources/36kr-quick.ts b/server/sources/36kr-quick.ts index 9e4d3a9..7ad63ca 100644 --- a/server/sources/36kr-quick.ts +++ b/server/sources/36kr-quick.ts @@ -1,3 +1,3 @@ -import { defineRSSSource } from "#/utils" +import { defineRSSHubSource } from "#/utils" -export default defineRSSSource("https://rsshub.rssforever.com/36kr/newsflashes") +export default defineRSSHubSource("/36kr/newsflashes") diff --git a/server/sources/36kr.ts b/server/sources/36kr.ts new file mode 100644 index 0000000..782ad10 --- /dev/null +++ b/server/sources/36kr.ts @@ -0,0 +1,5 @@ +import { defineRSSHubSource } from "#/utils" + +export default defineRSSHubSource("/36kr/hot-list", { + sorted: false, +}) diff --git a/server/sources/index.ts b/server/sources/index.ts index 555d7ca..37b493d 100644 --- a/server/sources/index.ts +++ b/server/sources/index.ts @@ -2,7 +2,9 @@ import type { SourceID, SourceInfo } from "@shared/types" import peopledaily from "./peopledaily" import weibo from "./weibo" import zaobao from "./zaobao" -import kr from "./36kr-quick" +import krQ from "./36kr-quick" +import wallstreetcn from "./wallstreetcn" +// import kr from "./36kr" export { fallback } from "./fallback" @@ -10,5 +12,7 @@ export const sources = { peopledaily, weibo, zaobao, - "36kr-quick": kr, + wallstreetcn, + "36kr-quick": krQ, + // "36kr": kr, } as Record Promise> diff --git a/server/sources/wallstreetcn.ts b/server/sources/wallstreetcn.ts new file mode 100644 index 0000000..da04998 --- /dev/null +++ b/server/sources/wallstreetcn.ts @@ -0,0 +1,3 @@ +import { defineRSSHubSource } from "#/utils" + +export default defineRSSHubSource("/wallstreetcn/live") diff --git a/server/utils/index.ts b/server/utils/index.ts index 5bbcda3..ac34503 100644 --- a/server/utils/index.ts +++ b/server/utils/index.ts @@ -1,4 +1,5 @@ -import type { NewsItem, SourceInfo } from "@shared/types" +import { RSSHubBase } from "@shared/consts" +import type { NewsItem, RSSHubInfo, SourceInfo } from "@shared/types" export function defineSource(source: () => Promise): () => Promise { return async () => ({ @@ -9,11 +10,11 @@ export function defineSource(source: () => Promise): () => Promise Promise { return async () => { - const source = await rss2json(url) - if (!source?.items.length) throw new Error("Cannot fetch data") + const data = await rss2json(url) + if (!data?.items.length) throw new Error("Cannot fetch data") return { - updatedTime: source.updatedTime ?? Date.now(), - items: source.items.slice(0, 20).map(item => ({ + updatedTime: data.updatedTime ?? Date.now(), + items: data.items.slice(0, 20).map(item => ({ title: item.title, url: item.link, id: item.link, @@ -24,3 +25,36 @@ export function defineRSSSource(url: string): () => Promise { } } } + +interface Option { + // default: true + sorted?: boolean + // default: 20 + limit?: number +} +export function defineRSSHubSource(route: string, option?: Option): () => Promise { + return async () => { + const url = new URL(route, RSSHubBase) + url.searchParams.set("format", "json") + const defaultOption: Option = { + sorted: true, + limit: 20, + } + Object.assign(defaultOption, option) + Object.entries(defaultOption).forEach(([key, value]) => { + url.searchParams.set(key, value.toString()) + }) + const data: RSSHubInfo = await $fetch(url) + return { + updatedTime: Date.now(), + items: data.items.slice(0, 20).map(item => ({ + title: item.title, + url: item.url, + id: item.id ?? item.url, + extra: { + date: item.date_published, + }, + })), + } + } +} diff --git a/shared/consts.ts b/shared/consts.ts index 88b3ac5..9e1c384 100644 --- a/shared/consts.ts +++ b/shared/consts.ts @@ -3,3 +3,6 @@ export const TTL = 15 * 60 * 1000 * 默认刷新间隔,否则复用缓存 */ export const Interval = 30 * 60 * 1000 + +export const RSSHubBase = "https://rsshub.rssforever.com" +// export const RSSHubBase = "https://rsshub.pseudoyu.com" diff --git a/shared/data.ts b/shared/data.ts index cb239c1..6bdd5ef 100644 --- a/shared/data.ts +++ b/shared/data.ts @@ -3,12 +3,18 @@ import type { Metadata } from "./types" export const sectionIds = ["focus", "social", "china", "world", "digital"] as const export const sources = { - "36kr": { - name: "36氪", - type: "人气榜", + "wallstreetcn": { + name: "华尔街见闻", interval: 10, - home: "https://36kr.com", + home: "https://wallstreetcn.com/", + type: "快讯", }, + // "36kr": { + // name: "36氪", + // type: "人气榜", + // interval: 10, + // home: "https://36kr.com", + // }, "36kr-quick": { name: "36氪", type: "快讯", @@ -83,19 +89,19 @@ export const metadata: Metadata = { sourceList: [], }, social: { - name: "社交媒体", - sourceList: ["douyin", "hupu", "tieba", "weibo"], + name: "实时", + sourceList: ["douyin", "weibo", "36kr-quick", "wallstreetcn", "zaobao"], }, china: { name: "国内", - sourceList: ["peopledaily", "36kr", "toutiao", "36kr-quick"], + sourceList: ["peopledaily", "toutiao"], }, world: { name: "国外", - sourceList: ["zaobao"], + sourceList: [], }, digital: { name: "数码", - sourceList: ["36kr"], + sourceList: [], }, } diff --git a/shared/types.ts b/shared/types.ts index cafb985..1c5973f 100644 --- a/shared/types.ts +++ b/shared/types.ts @@ -52,3 +52,18 @@ export interface CacheInfo { updated: number expires: number } + +export interface RSSHubInfo { + title: string + home_page_url: string + description: string + items: RSSHubItem[] +} + +export interface RSSHubItem { + id: string + url: string + title: string + content_html: string + date_published: string +}