chore: improve item.extra types
This commit is contained in:
Generated
+13
-6
@@ -209,7 +209,7 @@ importers:
|
||||
version: 0.20.5([email protected](@types/[email protected])([email protected]))([email protected](@types/[email protected]))([email protected])
|
||||
vite-plugin-with-nitro:
|
||||
specifier: 0.0.3
|
||||
version: 0.0.3([email protected])([email protected])([email protected](@types/[email protected])([email protected]))
|
||||
version: 0.0.3([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected]))
|
||||
vite-tsconfig-paths:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1([email protected])([email protected](@types/[email protected])([email protected]))
|
||||
@@ -3751,6 +3751,9 @@ packages:
|
||||
resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-8Sb3veuYCyrZL+VBt9LJfZjLUPWVvqn8tG28VqYNFCo43KHcKuq+b4EiXGeuaLAQWL2YmyDgMp2aSpH9JHsEQg==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==}
|
||||
|
||||
@@ -9870,6 +9873,9 @@ snapshots:
|
||||
dependencies:
|
||||
safer-buffer: 2.1.2
|
||||
|
||||
[email protected]:
|
||||
optional: true
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
@@ -10461,7 +10467,7 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]([email protected])([email protected]):
|
||||
[email protected]([email protected])([email protected])([email protected]):
|
||||
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([email protected])
|
||||
unstorage: 1.12.0([email protected])
|
||||
unstorage: 1.12.0([email protected])([email protected])
|
||||
untyped: 1.5.1
|
||||
unwasm: 0.3.9
|
||||
transitivePeerDependencies:
|
||||
@@ -11814,7 +11820,7 @@ snapshots:
|
||||
acorn: 8.13.0
|
||||
webpack-virtual-modules: 0.6.2
|
||||
|
||||
[email protected]([email protected]):
|
||||
[email protected]([email protected])([email protected]):
|
||||
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
|
||||
|
||||
[email protected]:
|
||||
@@ -11915,12 +11922,12 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
[email protected]([email protected])([email protected])([email protected](@types/[email protected])([email protected])):
|
||||
[email protected]([email protected])([email protected])([email protected])([email protected](@types/[email protected])([email protected])):
|
||||
dependencies:
|
||||
consola: 3.2.3
|
||||
defu: 6.1.4
|
||||
h3: [email protected]
|
||||
nitropack: [email protected]([email protected])([email protected])
|
||||
nitropack: [email protected]([email protected])([email protected])([email protected])
|
||||
vite: 5.4.10(@types/[email protected])([email protected])
|
||||
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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -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} />
|
||||
|
||||
Reference in New Issue
Block a user