diff --git a/public/icons/solidot.png b/public/icons/solidot.png new file mode 100644 index 0000000..02fd117 Binary files /dev/null and b/public/icons/solidot.png differ diff --git a/server/glob.d.ts b/server/glob.d.ts index aa23646..7fa0c2e 100644 --- a/server/glob.d.ts +++ b/server/glob.d.ts @@ -9,6 +9,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' { export const fastbull: typeof import('./sources/fastbull') export const gelonghui: typeof import('./sources/gelonghui') export const ithome: typeof import('./sources/ithome') + export const solidot: typeof import('./sources/solidot') export const sputniknewscn: typeof import('./sources/sputniknewscn') export const thepaper: typeof import('./sources/thepaper') export const tieba: typeof import('./sources/tieba') diff --git a/server/sources/solidot.ts b/server/sources/solidot.ts new file mode 100644 index 0000000..529ddd1 --- /dev/null +++ b/server/sources/solidot.ts @@ -0,0 +1,26 @@ +import * as cheerio from "cheerio" +import type { NewsItem } from "@shared/types" + +export default defineSource(async () => { + const baseURL = "https://www.solidot.org/" + const html: any = await $fetch(baseURL) + const $ = cheerio.load(html) + const $main = $(".block_m") + const news: NewsItem[] = [] + $main.each((_, el) => { + const a = $(el).find(".bg_htit a") + const url = a.attr("href") + const title = a.text() + const date_raw = $(el).find(".talk_time").text().match(/发表于(.*?分)/)?.[1] + const date = date_raw?.replace(/[年月]/g, "-").replace("时", ":").replace(/[分日]/g, "") + if (url && title && date) { + news.push({ + url: baseURL + url, + title, + id: url, + pubDate: parseRelativeDate(date, "Asia/Shanghai").valueOf(), + }) + } + }) + return news +}) diff --git a/shared/metadata.ts b/shared/metadata.ts index 593b4ec..d57e032 100644 --- a/shared/metadata.ts +++ b/shared/metadata.ts @@ -15,7 +15,7 @@ const originMetadata: Metadata = { }, tech: { name: "科技", - sources: ["ithome", "v2ex", "coolapk"], + sources: ["ithome", "v2ex", "coolapk", "solidot"], }, finance: { name: "财经", diff --git a/shared/sources.ts b/shared/sources.ts index b18f0e1..e18f96d 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -185,6 +185,12 @@ export const originSources = { }, }, }, + "solidot": { + name: "Solidot", + color: "sky", + home: "https://solidot.org", + interval: Time.Slow, + }, } as const satisfies Record export const sources = genSources()