mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-19 03:09:14 +08:00
feat(source): add hackernews
This commit is contained in:
parent
9420473d41
commit
46b9f0e28f
BIN
public/icons/hackernews.png
Normal file
BIN
public/icons/hackernews.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 387 B |
1
server/glob.d.ts
vendored
1
server/glob.d.ts
vendored
@ -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')
|
||||
|
29
server/sources/hackernews.ts
Normal file
29
server/sources/hackernews.ts
Normal 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
|
||||
})
|
@ -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]
|
||||
|
@ -15,7 +15,7 @@ const originMetadata: Metadata = {
|
||||
},
|
||||
tech: {
|
||||
name: "科技",
|
||||
sources: ["ithome", "v2ex", "coolapk", "solidot"],
|
||||
sources: ["hackernews", "v2ex", "ithome", "coolapk", "solidot"],
|
||||
},
|
||||
finance: {
|
||||
name: "财经",
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user