mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-19 03:09:14 +08:00
chore: improve item.extra types
This commit is contained in:
parent
76c282f302
commit
655204a14f
19
pnpm-lock.yaml
generated
19
pnpm-lock.yaml
generated
@ -209,7 +209,7 @@ importers:
|
||||
version: 0.20.5(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0))(workbox-build@7.1.1(@types/babel__core@7.20.5))(workbox-window@7.1.0)
|
||||
vite-plugin-with-nitro:
|
||||
specifier: 0.0.3
|
||||
version: 0.0.3(better-sqlite3@11.5.0)(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0))
|
||||
version: 0.0.3(better-sqlite3@11.5.0)(idb-keyval@6.2.1)(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0))
|
||||
vite-tsconfig-paths:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0))
|
||||
@ -3751,6 +3751,9 @@ packages:
|
||||
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
idb-keyval@6.2.1:
|
||||
resolution: {integrity: sha512-8Sb3veuYCyrZL+VBt9LJfZjLUPWVvqn8tG28VqYNFCo43KHcKuq+b4EiXGeuaLAQWL2YmyDgMp2aSpH9JHsEQg==}
|
||||
|
||||
idb@7.1.1:
|
||||
resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==}
|
||||
|
||||
@ -9870,6 +9873,9 @@ snapshots:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
|
||||
idb-keyval@6.2.1:
|
||||
optional: true
|
||||
|
||||
idb@7.1.1: {}
|
||||
|
||||
ieee754@1.2.1: {}
|
||||
@ -10461,7 +10467,7 @@ snapshots:
|
||||
|
||||
natural-compare@1.4.0: {}
|
||||
|
||||
nitro-go@0.0.1(better-sqlite3@11.5.0)(typescript@5.6.3):
|
||||
nitro-go@0.0.1(better-sqlite3@11.5.0)(idb-keyval@6.2.1)(typescript@5.6.3):
|
||||
dependencies:
|
||||
'@cloudflare/kv-asset-handler': 0.3.4
|
||||
'@netlify/functions': 2.8.2
|
||||
@ -10529,7 +10535,7 @@ snapshots:
|
||||
unctx: 2.3.1
|
||||
unenv: 1.10.0
|
||||
unimport: 3.13.1(rollup@4.24.0)
|
||||
unstorage: 1.12.0(ioredis@5.4.1)
|
||||
unstorage: 1.12.0(idb-keyval@6.2.1)(ioredis@5.4.1)
|
||||
untyped: 1.5.1
|
||||
unwasm: 0.3.9
|
||||
transitivePeerDependencies:
|
||||
@ -11814,7 +11820,7 @@ snapshots:
|
||||
acorn: 8.13.0
|
||||
webpack-virtual-modules: 0.6.2
|
||||
|
||||
unstorage@1.12.0(ioredis@5.4.1):
|
||||
unstorage@1.12.0(idb-keyval@6.2.1)(ioredis@5.4.1):
|
||||
dependencies:
|
||||
anymatch: 3.1.3
|
||||
chokidar: 3.6.0
|
||||
@ -11827,6 +11833,7 @@ snapshots:
|
||||
ofetch: 1.4.1
|
||||
ufo: 1.5.4
|
||||
optionalDependencies:
|
||||
idb-keyval: 6.2.1
|
||||
ioredis: 5.4.1
|
||||
|
||||
untun@0.1.3:
|
||||
@ -11915,12 +11922,12 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
vite-plugin-with-nitro@0.0.3(better-sqlite3@11.5.0)(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0)):
|
||||
vite-plugin-with-nitro@0.0.3(better-sqlite3@11.5.0)(idb-keyval@6.2.1)(typescript@5.6.3)(vite@5.4.10(@types/node@22.7.9)(terser@5.36.0)):
|
||||
dependencies:
|
||||
consola: 3.2.3
|
||||
defu: 6.1.4
|
||||
h3: h3-nightly@1.13.1-20241013-011028-3bf8af0
|
||||
nitropack: nitro-go@0.0.1(better-sqlite3@11.5.0)(typescript@5.6.3)
|
||||
nitropack: nitro-go@0.0.1(better-sqlite3@11.5.0)(idb-keyval@6.2.1)(typescript@5.6.3)
|
||||
vite: 5.4.10(@types/node@22.7.9)(terser@5.36.0)
|
||||
transitivePeerDependencies:
|
||||
- '@azure/app-configuration'
|
||||
|
@ -13,14 +13,14 @@ const quick = defineSource(async () => {
|
||||
const $a = $el.find("a.item-title")
|
||||
const url = $a.attr("href")
|
||||
const title = $a.text()
|
||||
const relativeDate = $el.find(".time")
|
||||
const relativeDate = $el.find(".time").text()
|
||||
if (url && title && relativeDate) {
|
||||
news.push({
|
||||
url: `${baseURL}${url}`,
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
date: parseRelativeDate(relativeDate.text()),
|
||||
date: parseRelativeDate(relativeDate, "Asia/Shanghai").valueOf(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ export default defineSource(async () => {
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
date: parseRelativeDate(relatieveTime, "Asia/Shanghai"),
|
||||
date: parseRelativeDate(relatieveTime, "Asia/Shanghai").valueOf(),
|
||||
info,
|
||||
},
|
||||
})
|
||||
|
@ -19,12 +19,10 @@ export default defineSource(async () => {
|
||||
url,
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
date: tranformToUTC(date),
|
||||
},
|
||||
pubDate: parseRelativeDate(date, "Asia/Shanghai").valueOf(),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return news.sort((m, n) => n.extra!.date > m.extra!.date ? 1 : -1)
|
||||
return news.sort((m, n) => n.pubDate! > m.pubDate! ? 1 : -1)
|
||||
})
|
||||
|
@ -33,7 +33,7 @@ export default defineSource(async () => {
|
||||
.map((k) => {
|
||||
const keyword = k.word_scheme ? k.word_scheme : `#${k.word}#`
|
||||
return {
|
||||
id: k.num,
|
||||
id: k.word,
|
||||
title: k.word,
|
||||
extra: {
|
||||
icon: k.icon && {
|
||||
|
@ -24,11 +24,9 @@ export default defineSource(async () => {
|
||||
url: base + url,
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
date: tranformToUTC(date),
|
||||
},
|
||||
pubDate: parseRelativeDate(date, "Asia/Shanghai").valueOf(),
|
||||
})
|
||||
}
|
||||
})
|
||||
return news.sort((m, n) => n.extra!.date > m.extra!.date ? 1 : -1)
|
||||
return news.sort((m, n) => n.pubDate! > m.pubDate! ? 1 : -1)
|
||||
})
|
||||
|
@ -24,7 +24,6 @@ export default defineSource({
|
||||
const url = "https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=20&desktop=true"
|
||||
const res: Res = await $fetch(url)
|
||||
return res.data
|
||||
.slice(0, 30)
|
||||
.map((k) => {
|
||||
return {
|
||||
id: k.target.id,
|
||||
|
@ -10,14 +10,12 @@ export function defineSource<T extends X>(source: T): T {
|
||||
export function defineRSSSource(url: string, option?: SourceOption): SourceGetter {
|
||||
return async () => {
|
||||
const data = await rss2json(url)
|
||||
if (!data?.items.length) throw new Error("Cannot fetch data")
|
||||
if (!data?.items.length) throw new Error("Cannot fetch rss data")
|
||||
return data.items.map(item => ({
|
||||
title: item.title,
|
||||
url: item.link,
|
||||
id: item.link,
|
||||
extra: {
|
||||
date: !option?.hiddenDate && item.created,
|
||||
},
|
||||
pubDate: !option?.hiddenDate ? item.created : undefined,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -40,9 +38,7 @@ export function defineRSSHubSource(route: string, RSSHubOptions?: RSSHubOption,
|
||||
title: item.title,
|
||||
url: item.url,
|
||||
id: item.id ?? item.url,
|
||||
extra: {
|
||||
date: !sourceOption?.hiddenDate && item.date_published,
|
||||
},
|
||||
pubDate: !sourceOption?.hiddenDate ? item.date_published : undefined,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,15 @@ export interface NewsItem {
|
||||
url: string
|
||||
mobileUrl?: string
|
||||
pubDate?: number | string
|
||||
extra?: Record<string, any>
|
||||
extra?: {
|
||||
hover?: string
|
||||
date?: number | string
|
||||
info?: false | string
|
||||
icon?: false | string | {
|
||||
url: string
|
||||
scale: number
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface SourceResponse {
|
||||
|
@ -167,10 +167,10 @@ function ExtraInfo({ item }: { item: NewsItem }) {
|
||||
return <>{item.extra.info}</>
|
||||
}
|
||||
if (item?.extra?.icon) {
|
||||
const { url, scale } = item.extra.icon
|
||||
const { url, scale } = typeof item.extra.icon === "string" ? { url: item.extra.icon, scale: undefined } : item.extra.icon
|
||||
return (
|
||||
<img
|
||||
src={url ?? item.extra.icon}
|
||||
src={url}
|
||||
style={{
|
||||
transform: `scale(${scale ?? 1})`,
|
||||
}}
|
||||
@ -181,7 +181,7 @@ function ExtraInfo({ item }: { item: NewsItem }) {
|
||||
}
|
||||
}
|
||||
|
||||
function NewsUpdatedTime({ date }: { date: string }) {
|
||||
function NewsUpdatedTime({ date }: { date: string | number }) {
|
||||
const relativeTime = useRelativeTime(date)
|
||||
return <>{relativeTime}</>
|
||||
}
|
||||
@ -226,7 +226,7 @@ function NewsListTimeLine({ items }: { items: NewsItem[] }) {
|
||||
<span className="flex items-center gap-1 text-neutral-400/50 ml--1px">
|
||||
<span className="">-</span>
|
||||
<span className="text-xs text-neutral-400/80">
|
||||
{(item.pubDate || item.extra?.date) && <NewsUpdatedTime date={item.pubDate || item?.extra?.date} />}
|
||||
{(item.pubDate || item?.extra?.date) && <NewsUpdatedTime date={(item.pubDate || item?.extra?.date)!} />}
|
||||
</span>
|
||||
<span className="text-xs text-neutral-400/80">
|
||||
<ExtraInfo item={item} />
|
||||
|
Loading…
x
Reference in New Issue
Block a user