From 46b9f0e28fdd68c3ca6264c10a8a3adbd8c9ef40 Mon Sep 17 00:00:00 2001 From: Ou Date: Fri, 25 Oct 2024 12:05:24 +0800 Subject: [PATCH] feat(source): add hackernews --- public/icons/hackernews.png | Bin 0 -> 387 bytes server/glob.d.ts | 1 + server/sources/hackernews.ts | 29 +++++++++++++++++++++++++++++ server/sources/solidot.ts | 4 ++-- shared/metadata.ts | 2 +- shared/sources.ts | 8 +++++++- 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 public/icons/hackernews.png create mode 100644 server/sources/hackernews.ts diff --git a/public/icons/hackernews.png b/public/icons/hackernews.png new file mode 100644 index 0000000000000000000000000000000000000000..8651170558cc6a1b3214baf2b7ecc45c4a53448c GIT binary patch literal 387 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|#^NA%Cx&(BWL^R}E~ycoX}-P; zT0k}j17mw80}DtA5K93u0|WB{Mh0de%?J`(zyy~STEL88gA~qMxhWJ#z4df)46zVQ z{xkpBhxv_M4V_$R4ZRXvY#R%W4ZiG6O~|M|aNt14lY~-rwzioE9`wxVGBueH;`Fq> zHZ|eKodX9Hbj}}0kZQc}B=+!u55gMTH;O5?9XVvep;DP3#eDcSI}gu3UI#v9=H^MN z%+0%$nGg5zv9;yDZ%CTKu-ozfe { + 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 +}) diff --git a/server/sources/solidot.ts b/server/sources/solidot.ts index 529ddd1..3d9c235 100644 --- a/server/sources/solidot.ts +++ b/server/sources/solidot.ts @@ -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] diff --git a/shared/metadata.ts b/shared/metadata.ts index d57e032..25816a6 100644 --- a/shared/metadata.ts +++ b/shared/metadata.ts @@ -15,7 +15,7 @@ const originMetadata: Metadata = { }, tech: { name: "科技", - sources: ["ithome", "v2ex", "coolapk", "solidot"], + sources: ["hackernews", "v2ex", "ithome", "coolapk", "solidot"], }, finance: { name: "财经", diff --git a/shared/sources.ts b/shared/sources.ts index e18f96d..93de7de 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -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 export const sources = genSources()