Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blue server #41

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example.env.server
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
G_CLIENT_ID=
G_CLIENT_SECRET=
JWT_SECRET=
G_CLIENT_ID=Ov23liR8HcDsGdKHq2I8
G_CLIENT_SECRET=7c9e75439e330488d3cdb2df963976d35f0e2bbf
JWT_SECRET=7c9e75439e330488d3cdb2df963976d35f0e2bbf
INIT_TABLE=true
ENABLE_CACHE=true
ENABLE_CACHE=true
4 changes: 2 additions & 2 deletions example.wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ compatibility_date = "2024-10-03"

[[d1_databases]]
binding = "NEWSNOW_DB"
database_name = "newsnow-db"
database_id = ""
database_name = "hot_news"
database_id = "5e83d319-1acf-4a26-b1e2-f9ca1868e157"
Binary file added public/icons/huxiu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions server/api/s/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SourceID, SourceResponse } from "@shared/types"
import { getters } from "#/getters"
import { getCacheTable } from "#/database/cache"
import { getters } from "#/getters"
import type { CacheInfo } from "#/types"

export default defineEventHandler(async (event): Promise<SourceResponse> => {
Expand All @@ -13,7 +13,7 @@ export default defineEventHandler(async (event): Promise<SourceResponse> => {
if (isValid(id)) {
const redirectID = sources?.[id]?.redirect
if (redirectID) id = redirectID
if (isValid(id)) throw new Error("Invalid source id")
if (isValid(id)) throw new Error(`Invalid source ${id}`)
}

const cacheTable = await getCacheTable()
Expand Down
1 change: 1 addition & 0 deletions server/glob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const gelonghui: typeof import('./sources/gelonghui')
export const github: typeof import('./sources/github')
export const hackernews: typeof import('./sources/hackernews')
export const huxiu: typeof import('./sources/huxiu')
export const ithome: typeof import('./sources/ithome')
export const jin10: typeof import('./sources/jin10')
export const kaopu: typeof import('./sources/kaopu')
Expand Down
32 changes: 32 additions & 0 deletions server/sources/_36kr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,40 @@ const quick = defineSource(async () => {

return news
})
const information = defineSource(async () => {
const baseURL = "https://www.36kr.com"
const url = `${baseURL}/information/web_news`
const response = await myFetch(url) as any
const $ = load(response)
const news: NewsItem[] = []

// 选择资讯页面的文章列表
const $items = $(".information-flow-item")
$items.each((_, el) => {
const $el = $(el)
const $a = $el.find(".article-item-title.weight-bold")
const url = $a.attr("href")
const title = $a.text().trim()
const time = $el.find(".kr-flow-bar-time").text().trim()

if (url && title && time) {
news.push({
url: url.startsWith("http") ? url : `${baseURL}${url}`,
title,
id: url,
extra: {
date: parseRelativeDate(time, "Asia/Shanghai").valueOf(),
info: "36氪资讯", // 添加标识
},
})
}
})

return news
})

export default defineSource({
"36kr": quick,
"36kr-quick": quick,
"36kr-information": information,
})
49 changes: 49 additions & 0 deletions server/sources/huxiu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { NewsItem } from "@shared/types"
import { load } from "cheerio"

const quick24 = defineSource(async () => {
const baseURL = "https://www.huxiu.com"
const url = `${baseURL}/article` // or moment
const response = await myFetch(url) as any
const $ = load(response)
const news: NewsItem[] = []
const $items = $(".article-item-wrap")
$items.each((_, el) => {
// 文字类
const $el = $(el)
const $a = $el.find("a.content-wrap")
const url = $a.attr("href")
const title = $a.find(".two-lines").text()
const relativeDate = $el.find(".bottom-line__time").text()
if (url && title && relativeDate) {
news.push({
url: `${url}`,
title,
id: url,
extra: {
date: parseRelativeDate(relativeDate, "Asia/Shanghai").valueOf(),
},
})
}
// 图片类
const c_title = $el.find(".channel-title").text().trim()
const c_url = $el.find(".article-item-wrap a").first().attr("href")
if (c_url && c_title && relativeDate) {
news.push({
url: `${c_url}`,
title: c_title,
id: c_url,
extra: {
date: parseRelativeDate(relativeDate, "Asia/Shanghai").valueOf(),
},
})
}
})

return news
})

export default defineSource({
"huxiu": quick24,
"huxiu-quick": quick24,
})
3 changes: 3 additions & 0 deletions shared/pinyin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"v2ex-share": "V2EX-zuixinfenxiang",
"huxiu-quick": "huxiuwang-kuaixun",
"36kr-quick": "36ke-kuaixun",
"36kr-information": "36ke-zixun",
"zhihu": "zhihu",
"weibo": "weibo-shishiresou",
"zaobao": "lianhezaobao",
Expand Down
53 changes: 40 additions & 13 deletions shared/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,43 @@ export const originSources = {
},
},
},
"huxiu": {
name: "虎嗅网",
// type: "realtime",
type: "hottest",
color: "blue",
// cloudflare pages cannot access
// disable: true,
home: "https://huxiu.com",
sub: {
quick: {
title: "快讯",
column: "finance",
},
},
},
"36kr": {
name: "36氪",
// type: "realtime",
type: "hottest",
color: "blue",
// cloudflare pages cannot access
// disable: true,
home: "https://36kr.com",
sub: {
quick: {
title: "快讯",
type: "hottest",
column: "finance",

},
information: {
title: "资讯",
type: "realtime",
column: "finance",
},
},
},
"zhihu": {
name: "知乎",
type: "hottest",
Expand Down Expand Up @@ -77,19 +114,7 @@ export const originSources = {
},
},
},
"36kr": {
name: "36氪",
type: "realtime",
color: "blue",
// cloudflare pages cannot access
disable: true,
home: "https://36kr.com",
sub: {
quick: {
title: "快讯",
},
},
},

"douyin": {
name: "抖音",
type: "hottest",
Expand Down Expand Up @@ -218,13 +243,15 @@ export const originSources = {
color: "orange",
column: "tech",
type: "hottest",
disable: true,
home: "https://news.ycombinator.com/",
},
"producthunt": {
name: "Product Hunt",
color: "red",
column: "tech",
type: "hottest",
disable: true,
home: "https://www.producthunt.com/",
},
"github": {
Expand Down
8 changes: 3 additions & 5 deletions src/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* prettier-ignore-start */

/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file is auto-generated by TanStack Router
// This file was automatically generated by TanStack Router.
// You should NOT make any changes in this file as it will be overwritten.
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.

// Import Routes

Expand Down Expand Up @@ -90,8 +90,6 @@ export const routeTree = rootRoute
._addFileChildren(rootRouteChildren)
._addFileTypes<FileRouteTypes>()

/* prettier-ignore-end */

/* ROUTE_MANIFEST_START
{
"routes": {
Expand Down