mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-19 03:09:14 +08:00
d7c8a38d88
fixed #20
36 lines
877 B
TypeScript
36 lines
877 B
TypeScript
import type { NewsItem } from "@shared/types"
|
|
import { load } from "cheerio"
|
|
|
|
const quick = defineSource(async () => {
|
|
const baseURL = "https://www.36kr.com"
|
|
const url = `${baseURL}/newsflashes`
|
|
const response = await myFetch(url) as any
|
|
const $ = load(response)
|
|
const news: NewsItem[] = []
|
|
const $items = $(".newsflash-item")
|
|
$items.each((_, el) => {
|
|
const $el = $(el)
|
|
const $a = $el.find("a.item-title")
|
|
const url = $a.attr("href")
|
|
const title = $a.text()
|
|
const relativeDate = $el.find(".time").text()
|
|
if (url && title && relativeDate) {
|
|
news.push({
|
|
url: `${baseURL}${url}`,
|
|
title,
|
|
id: url,
|
|
extra: {
|
|
date: parseRelativeDate(relativeDate, "Asia/Shanghai").valueOf(),
|
|
},
|
|
})
|
|
}
|
|
})
|
|
|
|
return news
|
|
})
|
|
|
|
export default defineSource({
|
|
"36kr": quick,
|
|
"36kr-quick": quick,
|
|
})
|