Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/glob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const pcbeta: typeof import('./sources/pcbeta')
export const producthunt: typeof import('./sources/producthunt')
export const qqvideo: typeof import('./sources/qqvideo')
export const sinafinance: typeof import('./sources/sinafinance')
export const smzdm: typeof import('./sources/smzdm')
export const solidot: typeof import('./sources/solidot')
export const sputniknewscn: typeof import('./sources/sputniknewscn')
Expand Down
55 changes: 55 additions & 0 deletions server/sources/sinafinance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"

const finance7x24 = defineSource(async () => {
// 真实 API 接口
const url = "https://app.cj.sina.com.cn/api/news/pc?page=1&size=30&tag=0"

// 获取接口数据
const responseData = await myFetch(url)

// 兼容处理:如果 myFetch 已经自动解析成了对象,就直接赋值;否则按字符串处理
let data: any
if (typeof responseData === "string") {
const jsonString = responseData.replace(/^[^{]*/, "").replace(/[^}]*$/, "")
data = JSON.parse(jsonString)
} else {
data = responseData // 已经是 JSON 对象,直接使用
}

const news: NewsItem[] = []
const list = data?.result?.data?.feed?.list || []

list.forEach((item: any) => {
if (!item.rich_text || !item.id) return

// rich_text 包含 HTML 标签(如 <a>),提取出纯文本作为标题
const $ = cheerio.load(item.rich_text)
const title = $.text().trim()

// 还原真实的wap详情端链接
const itemUrl = `https://wap.cj.sina.cn/pc/7x24/${item.id}`

// 解析时间,强制指定为东八区时间 (+0800)
const fixedDateStr = item.create_time.replace(/-/g, "/")
const pubDate = new Date(`${fixedDateStr} GMT+0800`).valueOf()

news.push({
id: item.id.toString(),
title,
url: itemUrl,
pubDate,
extra: {
date: pubDate,
},
})
})

// 按时间倒序排序,显式使用 Number() 确保算术运算的左右两侧都是数字
return news.sort((a, b) => Number(b.pubDate || 0) - Number(a.pubDate || 0))
})

export default defineSource({
"sinafinance": finance7x24,
"sinafinance-7x24": finance7x24,
})
1 change: 1 addition & 0 deletions shared/pinyin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"v2ex-share": "V2EX-zuixinfenxiang",
"zhihu": "zhihu",
"weibo": "weibo-shishiresou",
"sinafinance-7x24": "xinlangcaijing-7x24xiaoshi",
"zaobao": "lianhezaobao",
"coolapk": "kuan-jinrizuire",
"mktnews-flash": "MKTNews-kuaixun",
Expand Down
13 changes: 13 additions & 0 deletions shared/pre-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ export const originSources = {
interval: Time.Realtime,
home: "https://weibo.com",
},
"sinafinance": {
name: "新浪财经",
color: "red",
column: "finance",
home: "https://finance.sina.com.cn",
interval: Time.Realtime,
sub: {
"7x24": {
title: "7x24小时",
type: "realtime",
},
},
},
"zaobao": {
name: "联合早报",
interval: Time.Common,
Expand Down
19 changes: 19 additions & 0 deletions shared/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@
"color": "red",
"interval": 120000
},
"sinafinance": {
"redirect": "sinafinance-7x24",
"name": "新浪财经",
"type": "realtime",
"column": "finance",
"home": "https://finance.sina.com.cn",
"color": "red",
"interval": 120000,
"title": "7x24小时"
},
"sinafinance-7x24": {
"name": "新浪财经",
"type": "realtime",
"column": "finance",
"home": "https://finance.sina.com.cn",
"color": "red",
"interval": 120000,
"title": "7x24小时"
},
"zaobao": {
"name": "联合早报",
"type": "realtime",
Expand Down
90 changes: 28 additions & 62 deletions src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,34 @@
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.

// Import Routes
import { Route as rootRouteImport } from './routes/__root'
import { Route as IndexRouteImport } from './routes/index'
import { Route as CColumnRouteImport } from './routes/c.$column'

import { Route as rootRoute } from './routes/__root'
import { Route as IndexImport } from './routes/index'
import { Route as CColumnImport } from './routes/c.$column'

// Create/Update Routes

const IndexRoute = IndexImport.update({
const IndexRoute = IndexRouteImport.update({
id: '/',
path: '/',
getParentRoute: () => rootRoute,
getParentRoute: () => rootRouteImport,
} as any)

const CColumnRoute = CColumnImport.update({
const CColumnRoute = CColumnRouteImport.update({
id: '/c/$column',
path: '/c/$column',
getParentRoute: () => rootRoute,
getParentRoute: () => rootRouteImport,
} as any)

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexImport
parentRoute: typeof rootRoute
}
'/c/$column': {
id: '/c/$column'
path: '/c/$column'
fullPath: '/c/$column'
preLoaderRoute: typeof CColumnImport
parentRoute: typeof rootRoute
}
}
}

// Create and export the route tree

export interface FileRoutesByFullPath {
'/': typeof IndexRoute
'/c/$column': typeof CColumnRoute
}

export interface FileRoutesByTo {
'/': typeof IndexRoute
'/c/$column': typeof CColumnRoute
}

export interface FileRoutesById {
__root__: typeof rootRoute
__root__: typeof rootRouteImport
'/': typeof IndexRoute
'/c/$column': typeof CColumnRoute
}

export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: '/' | '/c/$column'
Expand All @@ -75,37 +44,34 @@ export interface FileRouteTypes {
id: '__root__' | '/' | '/c/$column'
fileRoutesById: FileRoutesById
}

export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
CColumnRoute: typeof CColumnRoute
}

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
'/c/$column': {
id: '/c/$column'
path: '/c/$column'
fullPath: '/c/$column'
preLoaderRoute: typeof CColumnRouteImport
parentRoute: typeof rootRouteImport
}
}
}

const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
CColumnRoute: CColumnRoute,
}

export const routeTree = rootRoute
export const routeTree = rootRouteImport
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

/* ROUTE_MANIFEST_START
{
"routes": {
"__root__": {
"filePath": "__root.tsx",
"children": [
"/",
"/c/$column"
]
},
"/": {
"filePath": "index.tsx"
},
"/c/$column": {
"filePath": "c.$column.tsx"
}
}
}
ROUTE_MANIFEST_END */