-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Expand file tree
/
Copy pathsamr.ts
More file actions
34 lines (28 loc) · 927 Bytes
/
Copy pathsamr.ts
File metadata and controls
34 lines (28 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
const sourceURL = "https://www.samrdprc.org.cn/qczh/gnzhqc/"
export function parseSamrRecalls(html: string): NewsItem[] {
const $ = cheerio.load(html)
const news: NewsItem[] = []
$(".boxl_ul li").each((_, element) => {
const anchor = $(element).find("a").first()
const href = anchor.attr("href")
const title = anchor.attr("title")?.trim() || anchor.text().trim()
const date = $(element).text().match(/\d{4}-\d{2}-\d{2}/)?.[0]
if (!href || !title) return
const url = new URL(href, sourceURL).toString()
news.push({
id: url,
title,
url,
pubDate: date ? `${date}T00:00:00+08:00` : undefined,
})
})
return news
}
export default defineSource(async () => {
const html = await myFetch<string>(sourceURL, {
responseType: "text" as any,
})
return parseSamrRecalls(html)
})