Skip to content

Commit

Permalink
feat(source): add linux.do
Browse files Browse the repository at this point in the history
  • Loading branch information
ourongxing committed Dec 1, 2024
1 parent 94068b8 commit 3b843c3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
Binary file added public/icons/linuxdo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions scripts/favicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions server/glob.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
61 changes: 61 additions & 0 deletions server/sources/linuxdo.ts
Original file line number Diff line number Diff line change
@@ -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,
})
4 changes: 3 additions & 1 deletion shared/pinyin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
18 changes: 18 additions & 0 deletions shared/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3b843c3

Please sign in to comment.