mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-31 10:58:04 +08:00
feat: new sources
This commit is contained in:
parent
a12aed723f
commit
ad2ff17a0d
@ -1,16 +1,21 @@
|
||||
import type { NewsItem, SourceID } from "@shared/types"
|
||||
import weibo from "./weibo"
|
||||
import zaobao from "./zaobao"
|
||||
import v2ex from "./v2ex"
|
||||
import ithome from "./ithome"
|
||||
|
||||
export const sourcesFn = {
|
||||
weibo,
|
||||
zaobao,
|
||||
v2ex,
|
||||
ithome,
|
||||
"peopledaily": defineRSSSource("https://feedx.net/rss/people.xml", {
|
||||
hiddenDate: true,
|
||||
}),
|
||||
weibo,
|
||||
"sputniknewscn": defineRSSHubSource("/sputniknews/news/chinese"),
|
||||
"douyin": defineFallbackSource("douyin"),
|
||||
zaobao,
|
||||
"aljazeeracn": defineRSSSource("https://feedx.net/rss/aljazeera.xml"),
|
||||
"toutiao": defineFallbackSource("toutiao"),
|
||||
"wallstreetcn": defineRSSHubSource("/wallstreetcn/live"),
|
||||
"36kr-quick": defineRSSHubSource("/36kr/newsflashes"),
|
||||
// "36kr": kr,
|
||||
} as Record<SourceID, () => Promise<NewsItem[]>>
|
||||
|
32
server/sources/ithome.ts
Normal file
32
server/sources/ithome.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import * as cheerio from "cheerio"
|
||||
import type { NewsItem } from "@shared/types"
|
||||
import { $fetch } from "ofetch"
|
||||
|
||||
export default defineSource(async () => {
|
||||
const response = await $fetch("https://www.ithome.com/list/")
|
||||
const $ = cheerio.load(response)
|
||||
const $main = $("#list > div.fl > ul > li")
|
||||
const news: NewsItem[] = []
|
||||
$main.each((_, el) => {
|
||||
const $el = $(el)
|
||||
const $a = $el.find("a.t")
|
||||
const url = $a.attr("href")
|
||||
const title = $a.text()
|
||||
const date = $(el).find("i").text()
|
||||
if (url && title && date) {
|
||||
const isAd = url?.includes("lapin") || ["神券", "优惠", "补贴", "京东"].find(k => title.includes(k))
|
||||
if (!isAd) {
|
||||
news.push({
|
||||
url,
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
date: tranformToUTC(date),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return news.sort((m, n) => n.extra!.date > m.extra!.data ? 1 : -1)
|
||||
.slice(0, 20)
|
||||
})
|
30
server/sources/v2ex.ts
Normal file
30
server/sources/v2ex.ts
Normal file
@ -0,0 +1,30 @@
|
||||
interface Res {
|
||||
version: string
|
||||
title: string
|
||||
description: string
|
||||
home_page_url: string
|
||||
feed_url: string
|
||||
icon: string
|
||||
favicon: string
|
||||
items: {
|
||||
url: string
|
||||
date_modified?: string
|
||||
content_html: string
|
||||
date_published: string
|
||||
title: string
|
||||
id: string
|
||||
}[]
|
||||
}
|
||||
|
||||
export default defineSource(async () => {
|
||||
const res = await Promise.all(["create", "ideas", "programmer", "share"].map(k => $fetch(`https://www.v2ex.com/feed/${k}.json`) as Promise< Res>))
|
||||
if (!res?.[0]?.items?.length) throw new Error("Cannot fetch data")
|
||||
return res.map(k => k.items).flat().map(k => ({
|
||||
id: k.id,
|
||||
title: k.title,
|
||||
extra: {
|
||||
date: k.date_modified ?? k.date_published,
|
||||
},
|
||||
url: k.url,
|
||||
})).sort((m, n) => m.extra.date < n.extra.date ? 1 : -1).slice(0, 20)
|
||||
})
|
@ -25,17 +25,11 @@ export default defineSource(async () => {
|
||||
title,
|
||||
id: url,
|
||||
extra: {
|
||||
origin: date,
|
||||
date: tranformToUTC(date),
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
return news.sort((m, n) => n.extra!.origin > m.extra!.origin ? 1 : -1)
|
||||
return news.sort((m, n) => n.extra!.date > m.extra!.date ? 1 : -1)
|
||||
.slice(0, 20)
|
||||
.map(item => ({
|
||||
...item,
|
||||
extra: {
|
||||
date: tranformToUTC(item.extra!.origin),
|
||||
},
|
||||
}))
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user