feat(source): add linux.do

This commit is contained in:
Ou 2024-12-01 13:01:58 +08:00
parent 94068b899a
commit 3b843c39d3
6 changed files with 84 additions and 6 deletions

BIN
public/icons/linuxdo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

View File

@ -3,7 +3,6 @@ import fs from "node:fs"
import { fileURLToPath } from "node:url"
import { join } from "node:path"
import { Buffer } from "node:buffer"
import { getLogos } from "favicons-scraper"
import { consola } from "consola"
import { originSources } from "../shared/sources"
@ -34,10 +33,7 @@ async function main() {
return
}
if (!source.home) return
const res = await getLogos(source.home)
if (res.length) {
await downloadImage(res[0].src, icon, id)
}
await downloadImage(`https://icons.duckduckgo.com/ip3/${source.home.replace(/^https?:\/\//, "").replace(/\/$/, "")}.ico`, icon, id)
} catch (e) {
consola.error(id, "\n", e)
}

1
server/glob.d.ts vendored
View File

@ -16,6 +16,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
export const jin10: typeof import('./sources/jin10')
export const kaopu: typeof import('./sources/kaopu')
export const kuaishou: typeof import('./sources/kuaishou')
export const linuxdo: typeof import('./sources/linuxdo')
export const producthunt: typeof import('./sources/producthunt')
export const solidot: typeof import('./sources/solidot')
export const sputniknewscn: typeof import('./sources/sputniknewscn')

61
server/sources/linuxdo.ts Normal file
View File

@ -0,0 +1,61 @@
interface Res {
topic_list: {
can_create_topic: boolean
more_topics_url: string
per_page: number
top_tags: string[]
topics: {
id: number
title: string
fancy_title: string
posts_count: number
reply_count: number
highest_post_number: number
image_url: null | string
created_at: Date
last_posted_at: Date
bumped: boolean
bumped_at: Date
unseen: boolean
pinned: boolean
excerpt?: string
visible: boolean
closed: boolean
archived: boolean
like_count: number
has_summary: boolean
last_poster_username: string
category_id: number
pinned_globally: boolean
}[]
}
}
const hot = defineSource(async () => {
const res = await myFetch<Res>("https://linux.do/top/daily.json")
return res.topic_list.topics
.filter(k => k.visible && !k.archived && !k.pinned)
.map(k => ({
id: k.id,
title: k.title,
url: `https://linux.do/t/topic/${k.id}`,
}))
})
const latest = defineSource(async () => {
const res = await myFetch<Res>("https://linux.do/latest.json?order=created")
return res.topic_list.topics
.filter(k => k.visible && !k.archived && !k.pinned)
.map(k => ({
id: k.id,
title: k.title,
pubDate: new Date(k.created_at).valueOf(),
url: `https://linux.do/t/topic/${k.id}`,
}))
})
export default defineSource({
"linuxdo": latest,
"linuxdo-latest": latest,
"linuxdo-hot": hot,
})

View File

@ -27,5 +27,7 @@
"bilibili-hot-search": "bilibili-resou",
"kaopu": "kaopuxinwen",
"jin10": "jinshishuju",
"baidu": "baiduresou"
"baidu": "baiduresou",
"linuxdo-latest": "Linux DO-zuixin",
"linuxdo-hot": "Linux DO-remen"
}

View File

@ -282,6 +282,24 @@ export const originSources = {
type: "hottest",
home: "https://www.baidu.com",
},
"linuxdo": {
name: "LINUX DO",
column: "tech",
color: "slate",
home: "https://linux.do/",
sub: {
latest: {
title: "最新",
home: "https://linux.do/latest",
},
hot: {
title: "今日最热",
type: "hottest",
interval: Time.Common,
home: "https://linux.do/hot",
},
},
},
} as const satisfies Record<string, OriginSource>
export const sources = genSources()