feat(source): add hackernews

This commit is contained in:
Ou 2024-10-25 12:05:24 +08:00
parent 9420473d41
commit 46b9f0e28f
6 changed files with 40 additions and 4 deletions

BIN
public/icons/hackernews.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

1
server/glob.d.ts vendored
View File

@ -8,6 +8,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const douyin: typeof import('./sources/douyin')
export const fastbull: typeof import('./sources/fastbull')
export const gelonghui: typeof import('./sources/gelonghui')
export const hackernews: typeof import('./sources/hackernews')
export const ithome: typeof import('./sources/ithome')
export const solidot: typeof import('./sources/solidot')
export const sputniknewscn: typeof import('./sources/sputniknewscn')

View File

@ -0,0 +1,29 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
export default defineSource(async () => {
const baseURL = "https://news.ycombinator.com"
const html: any = await $fetch(baseURL)
const $ = cheerio.load(html)
const $main = $(".athing")
const news: NewsItem[] = []
$main.each((_, el) => {
const a = $(el).find(".titleline a").first()
// const url = a.attr("href")
const title = a.text()
const id = $(el).attr("id")
const score = $(`#score_${id}`).text()
const url = `${baseURL}/item?id=${id}`
if (url && id && title) {
news.push({
url,
title,
id,
extra: {
info: score,
},
})
}
})
return news
})

View File

@ -2,13 +2,13 @@ import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
export default defineSource(async () => {
const baseURL = "https://www.solidot.org/"
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 a = $(el).find(".bg_htit a").last()
const url = a.attr("href")
const title = a.text()
const date_raw = $(el).find(".talk_time").text().match(/发表于(.*?分)/)?.[1]

View File

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

View File

@ -187,10 +187,16 @@ export const originSources = {
},
"solidot": {
name: "Solidot",
color: "sky",
color: "teal",
home: "https://solidot.org",
interval: Time.Slow,
},
"hackernews": {
name: "Hacker News",
color: "orange",
type: "hottest",
home: "https://news.ycombinator.com/",
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()