feat(source): add solidot.org

This commit is contained in:
Ou 2024-10-25 11:46:53 +08:00
parent 28efd23dfa
commit 9420473d41
5 changed files with 34 additions and 1 deletions

BIN
public/icons/solidot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

1
server/glob.d.ts vendored
View File

@ -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')

26
server/sources/solidot.ts Normal file
View File

@ -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
})

View File

@ -15,7 +15,7 @@ const originMetadata: Metadata = {
},
tech: {
name: "科技",
sources: ["ithome", "v2ex", "coolapk"],
sources: ["ithome", "v2ex", "coolapk", "solidot"],
},
finance: {
name: "财经",

View File

@ -185,6 +185,12 @@ export const originSources = {
},
},
},
"solidot": {
name: "Solidot",
color: "sky",
home: "https://solidot.org",
interval: Time.Slow,
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()