feat: 新增实时news-果核剥壳 (#106)

Co-authored-by: daixin <[email protected]>
This commit is contained in:
dxxxxxxx
2025-04-04 19:20:39 +08:00
committed by GitHub
co-authored by daixin
parent df7ecbc5e6
commit aca476dd8f
6 changed files with 147 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

+1
View File
@@ -10,6 +10,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 ghxi: typeof import('./sources/ghxi')
export const github: typeof import('./sources/github')
export const hackernews: typeof import('./sources/hackernews')
export const ithome: typeof import('./sources/ithome')
+57
View File
@@ -0,0 +1,57 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
const relativeTimeToDate = function (timeStr) {
const units = {
: 1000,
分钟: 60 * 1000,
小时: 60 * 60 * 1000,
: 24 * 60 * 60 * 1000,
: 7 * 24 * 60 * 60 * 1000,
: 30 * 24 * 60 * 60 * 1000,
: 365 * 24 * 60 * 60 * 1000,
}
const match = timeStr.match(/^(\d+)\s*([秒天周月年]|分钟|小时)/)
if (!match) {
return ""
}
const num = Number.parseInt(match[1])
const unit = match[2]
const msAgo = num * units[unit]
return new Date(Date.now() - msAgo).valueOf()
}
export default defineSource(async () => {
const html: any = await myFetch("https://www.ghxi.com/category/all")
const $ = cheerio.load(html)
const news: NewsItem[] = []
$(".sec-panel .sec-panel-body .post-loop li").each((i, elem) => {
let summary_title = $(elem).find(".item-content .item-title").text()
if (summary_title) {
summary_title = summary_title.trim()
summary_title = summary_title.replaceAll("'", "''")
}
let summary_description = $(elem).find(".item-content .item-excerpt").text()
if (summary_description) {
summary_description = summary_description.trim()
summary_description = summary_description.replaceAll("'", "''")
}
const date = $(elem).find(".item-content .date").text()
console.log(date)
const url = $(elem).find(".item-content .item-title a").attr("href")
news.push({
id: url,
url,
title: summary_title,
extra: {
hover: summary_description,
date: relativeTimeToDate(date),
},
})
})
return news
})
+7 -1
View File
@@ -7,11 +7,13 @@
"wallstreetcn-quick": "huaerjiejianwen-shishikuaixun",
"wallstreetcn-news": "huaerjiejianwen-zuixinzixun",
"wallstreetcn-hot": "huaerjiejianwen-zuirewenzhang",
"36kr-quick": "36ke-kuaixun",
"douyin": "douyin",
"tieba": "baidutieba-reyi",
"toutiao": "jinritoutiao",
"ithome": "ITzhijia",
"thepaper": "pengpaixinwen-rebang",
"sputniknewscn": "weixingtongxunshe",
"cankaoxiaoxi": "cankaoxiaoxi",
"cls-telegraph": "cailianshe-dianbao",
"cls-depth": "cailianshe-shendu",
@@ -25,7 +27,11 @@
"producthunt": "Product Hunt",
"github-trending-today": "Github-Today",
"bilibili-hot-search": "bilibili-resou",
"kuaishou": "kuaishou",
"kaopu": "kaopuxinwen",
"jin10": "jinshishuju",
"baidu": "baiduresou"
"baidu": "baiduresou",
"linuxdo-latest": "LINUX DO-zuixin",
"linuxdo-hot": "LINUX DO-jinrizuire",
"ghxi": "guoheboke"
}
+7
View File
@@ -305,6 +305,13 @@ export const originSources = {
},
},
},
"ghxi": {
name: "果核剥壳",
column: "china",
color: "green",
type: "realtime",
home: "https://www.ghxi.com/",
},
} as const satisfies Record<string, OriginSource>
export function genSources() {
+75
View File
@@ -87,6 +87,27 @@
"interval": 1800000,
"title": "最热文章"
},
"36kr": {
"redirect": "36kr-quick",
"name": "36氪",
"type": "realtime",
"disable": "cf",
"column": "tech",
"home": "https://36kr.com",
"color": "blue",
"interval": 600000,
"title": "快讯"
},
"36kr-quick": {
"name": "36氪",
"type": "realtime",
"disable": "cf",
"column": "tech",
"home": "https://36kr.com",
"color": "blue",
"interval": 600000,
"title": "快讯"
},
"douyin": {
"name": "抖音",
"type": "hottest",
@@ -129,6 +150,14 @@
"color": "gray",
"interval": 1800000
},
"sputniknewscn": {
"name": "卫星通讯社",
"disable": "cf",
"column": "world",
"home": "https://sputniknews.cn",
"color": "orange",
"interval": 600000
},
"cankaoxiaoxi": {
"name": "参考消息",
"column": "world",
@@ -288,6 +317,15 @@
"interval": 600000,
"title": "热搜"
},
"kuaishou": {
"name": "快手",
"type": "hottest",
"disable": "cf",
"column": "china",
"home": "https://www.kuaishou.com",
"color": "orange",
"interval": 600000
},
"kaopu": {
"name": "靠谱新闻",
"desc": "不一定靠谱,多看多思考",
@@ -311,5 +349,42 @@
"home": "https://www.baidu.com",
"color": "blue",
"interval": 600000
},
"linuxdo": {
"redirect": "linuxdo-latest",
"name": "LINUX DO",
"disable": "cf",
"column": "tech",
"home": "https://linux.do/latest",
"color": "slate",
"interval": 600000,
"title": "最新"
},
"linuxdo-latest": {
"name": "LINUX DO",
"disable": "cf",
"column": "tech",
"home": "https://linux.do/latest",
"color": "slate",
"interval": 600000,
"title": "最新"
},
"linuxdo-hot": {
"name": "LINUX DO",
"type": "hottest",
"disable": "cf",
"column": "tech",
"home": "https://linux.do/hot",
"color": "slate",
"interval": 1800000,
"title": "今日最热"
},
"ghxi": {
"name": "果核剥壳",
"type": "realtime",
"column": "china",
"home": "https://www.ghxi.com/",
"color": "green",
"interval": 600000
}
}