2024-10-09 15:50:14 +08:00
|
|
|
import type { NewsItem } from "@shared/types"
|
|
|
|
import { load } from "cheerio"
|
|
|
|
|
|
|
|
export default defineSource(async () => {
|
|
|
|
const url = "https://www.36kr.com/newsflashes"
|
2024-10-14 17:18:57 +08:00
|
|
|
const response = await $fetch(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()
|
|
|
|
const relativeDate = $el.find(".time")
|
|
|
|
if (url && title && relativeDate) {
|
|
|
|
news.push({
|
2024-10-11 18:47:27 +08:00
|
|
|
url: `https://www.36kr.com${url}`,
|
2024-10-09 15:50:14 +08:00
|
|
|
title,
|
|
|
|
id: url,
|
|
|
|
extra: {
|
|
|
|
date: parseRelativeDate(relativeDate.text()),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-10-13 13:59:23 +08:00
|
|
|
return news.slice(0, 30)
|
2024-10-09 15:50:14 +08:00
|
|
|
})
|