36 lines
877 B
TypeScript
Raw Normal View History

2024-10-09 15:50:14 +08:00
import type { NewsItem } from "@shared/types"
import { load } from "cheerio"
2024-10-20 20:28:49 +08:00
const quick = defineSource(async () => {
2024-10-21 01:38:58 +08:00
const baseURL = "https://www.36kr.com"
const url = `${baseURL}/newsflashes`
const response = await myFetch(url) as any
2024-10-09 15:50:14 +08:00
const $ = load(response)
const news: NewsItem[] = []
2024-10-10 22:47:25 +08:00
const $items = $(".newsflash-item")
2024-10-09 15:50:14 +08:00
$items.each((_, el) => {
const $el = $(el)
2024-10-11 18:47:27 +08:00
const $a = $el.find("a.item-title")
2024-10-09 15:50:14 +08:00
const url = $a.attr("href")
const title = $a.text()
2024-10-27 22:09:17 +08:00
const relativeDate = $el.find(".time").text()
2024-10-09 15:50:14 +08:00
if (url && title && relativeDate) {
news.push({
2024-10-21 01:38:58 +08:00
url: `${baseURL}${url}`,
2024-10-09 15:50:14 +08:00
title,
id: url,
extra: {
2024-10-27 22:09:17 +08:00
date: parseRelativeDate(relativeDate, "Asia/Shanghai").valueOf(),
2024-10-09 15:50:14 +08:00
},
})
}
})
2024-10-20 20:28:49 +08:00
return news
})
export default defineSource({
"36kr": quick,
"36kr-quick": quick,
2024-10-09 15:50:14 +08:00
})