Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/glob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const pcbeta: typeof import('./sources/pcbeta')
export const producthunt: typeof import('./sources/producthunt')
export const qqvideo: typeof import('./sources/qqvideo')
export const samr: typeof import('./sources/samr')
export const smzdm: typeof import('./sources/smzdm')
export const solidot: typeof import('./sources/solidot')
export const sputniknewscn: typeof import('./sources/sputniknewscn')
Expand Down
34 changes: 34 additions & 0 deletions server/sources/samr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})
1 change: 1 addition & 0 deletions shared/pinyin.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"toutiao": "jinritoutiao",
"ithome": "ITzhijia",
"thepaper": "pengpaixinwen-rebang",
"samr": "guojiashichangjianguanzongju-guoneiqichezhaohui",
"sputniknewscn": "weixingtongxunshe",
"cankaoxiaoxi": "cankaoxiaoxi",
"pcbeta-windows11": "yuanjingluntan-Win11",
Expand Down
9 changes: 9 additions & 0 deletions shared/pre-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ export const originSources = {
color: "gray",
home: "https://www.thepaper.cn",
},
"samr": {
name: "国家市场监管总局",
title: "国内汽车召回",
interval: Time.Common,
type: "realtime",
column: "china",
color: "red",
home: "https://www.samrdprc.org.cn/qczh/gnzhqc/",
},
"sputniknewscn": {
name: "卫星通讯社",
color: "orange",
Expand Down
9 changes: 9 additions & 0 deletions shared/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@
"color": "gray",
"interval": 1800000
},
"samr": {
"title": "国内汽车召回",
"name": "国家市场监管总局",
"type": "realtime",
"column": "china",
"home": "https://www.samrdprc.org.cn/qczh/gnzhqc/",
"color": "red",
"interval": 1800000
},
"sputniknewscn": {
"name": "卫星通讯社",
"column": "world",
Expand Down
3 changes: 2 additions & 1 deletion shared/updated-sources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const updatedSourceIds = [
"samr",
"dongqiudi",
"producthunt",
"aihot",
Expand All @@ -20,5 +21,5 @@ export const updatedSourceIds = [
"bilibili-hot-video",
"bilibili-ranking",
"kuaishou",
"toutiao"
"toutiao",
] as const
29 changes: 29 additions & 0 deletions test/samr.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from "vitest"
import { parseSamrRecalls } from "../server/sources/samr"

describe("parseSamrRecalls", () => {
it("parses official recall entries", () => {
const html = `
<div class="boxl_ul">
<ul>
<li>
<a href="./202607/t20260730_115807.html"
title="广汽丰田汽车有限公司召回部分铂智7汽车">
广汽丰田汽车有限公司召回部分铂智7汽车
</a>
<span>2026-07-31</span>
</li>
</ul>
</div>
`

expect(parseSamrRecalls(html)).toEqual([
{
id: "https://www.samrdprc.org.cn/qczh/gnzhqc/202607/t20260730_115807.html",
title: "广汽丰田汽车有限公司召回部分铂智7汽车",
url: "https://www.samrdprc.org.cn/qczh/gnzhqc/202607/t20260730_115807.html",
pubDate: "2026-07-31T00:00:00+08:00",
},
])
})
})