feat: add source gelonghui

This commit is contained in:
Ou
2024-10-21 03:05:50 +08:00
parent 8e99430d0f
commit 4f34b7fdfc
6 changed files with 43 additions and 5 deletions
+31
View File
@@ -0,0 +1,31 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
export default defineSource(async () => {
const baseURL = "https://www.gelonghui.com"
const html: any = await $fetch("https://www.gelonghui.com/news")
const $ = cheerio.load(html)
const $main = $(".article-content")
const news: NewsItem[] = []
$main.each((_, el) => {
const a = $(el).find(".detail-right>a")
// https://www.kzaobao.com/shiju/20241002/170659.html
const url = a.attr("href")
const title = a.find("h2").text()
const info = $(el).find(".about-stocks").text()
// 第三个 p
const relatieveTime = $(el).find(".time > span:nth-child(3)").text()
if (url && title && relatieveTime) {
news.push({
url: baseURL + url,
title,
id: url,
extra: {
date: parseRelativeDate(relatieveTime).toDateString(),
info,
},
})
}
})
return news.sort((m, n) => n.extra!.date > m.extra!.date ? 1 : -1)
})
+2
View File
@@ -13,6 +13,7 @@ import toutiao from "./toutiao"
import cls from "./cls"
import sputniknewscn from "./sputniknewscn"
import xueqiu from "./xueqiu"
import gelonghui from "./gelonghui"
import type { SourceGetter } from "#/types"
export const sourcesGetters = {
@@ -26,6 +27,7 @@ export const sourcesGetters = {
sputniknewscn,
...wallstreetcn,
...xueqiu,
gelonghui,
douyin,
...cls,
toutiao,
+1 -2
View File
@@ -1,9 +1,8 @@
import * as cheerio from "cheerio"
import type { NewsItem } from "@shared/types"
import { $fetch } from "ofetch"
export default defineSource(async () => {
const response = await $fetch("https://www.ithome.com/list/")
const response: any = await $fetch("https://www.ithome.com/list/")
const $ = cheerio.load(response)
const $main = $("#list > div.fl > ul > li")
const news: NewsItem[] = []
+1 -2
View File
@@ -164,7 +164,6 @@ export function parseRelativeDate(date: string) {
if (beforeMatches) {
matches.push(beforeMatches[1])
// duration 这个插件有 bug,他会重新实现 subtract 这个方法,并且不会处理 weeks。用 ms 就可以调用默认的方法
// 改成这样之后,月又出问题了,我也是服了
return dayjs().subtract(dayjs.duration(toDurations(matches))).toDate()
}
@@ -218,5 +217,5 @@ export function parseRelativeDate(date: string) {
}
}
return date
return new Date()
}
+1 -1
View File
@@ -19,7 +19,7 @@ const originMetadata: Metadata = {
},
finance: {
name: "财经",
sources: ["cls-telegraph", "cls-depth", "wallstreetcn", "wallstreetcn-hot", "wallstreetcn-news", "xueqiu-hotstock"],
sources: ["cls-telegraph", "cls-depth", "wallstreetcn", "wallstreetcn-hot", "wallstreetcn-news", "xueqiu-hotstock", "gelonghui"],
},
focus: {
name: "关注",
+7
View File
@@ -157,6 +157,13 @@ export const originSources = {
},
},
},
"gelonghui": {
name: "格隆汇",
color: "blue",
title: "事件",
interval: Time.Realtime,
home: "https://www.gelonghui.com",
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()