Skip to content

Commit

Permalink
✨ feat: 新增 LinuxDo
Browse files Browse the repository at this point in the history
✨ feat: 新增 LinuxDo
  • Loading branch information
imsyy authored Jan 9, 2025
2 parents c9ee406 + c1b21f1 commit 0fa3108
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ dist
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
.nvmrc
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"devDependencies": {
"@eslint/js": "^9.16.0",
"@types/cheerio": "^0.22.35",
"@types/md5": "^2.3.5",
"@types/node": "^22.10.1",
"@types/user-agents": "^1.0.4",
Expand Down
8 changes: 8 additions & 0 deletions src/router.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,12 @@ export type RouterType = {
}[];
};
};
linuxdo: {
id: string;
title: string;
url: string;
author: string;
desc: string;
timestamp: string;
};
};
57 changes: 57 additions & 0 deletions src/routes/linuxdo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { RouterData } from "../types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";

interface Topic {
id: number;
title: string;
excerpt: string;
last_poster_username: string;
created_at: string;
views: number;
like_count: number;
}

export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
const routeData: RouterData = {
name: "linuxdo",
title: "Linux.do",
type: "热门文章",
description: "Linux 技术社区热搜",
link: "https://linux.do/hot",
total: listData.data?.length || 0,
...listData,
};
return routeData;
};

const getList = async (noCache: boolean) => {
const url = "https://linux.do/top/weekly.json";
const result = await get({
url,
noCache,
headers: {
"Accept": "application/json",
}
});

const topics = result.data.topic_list.topics as Topic[];
const list = topics.map((topic) => {
return {
id: topic.id,
title: topic.title,
desc: topic.excerpt,
author: topic.last_poster_username,
timestamp: getTime(topic.created_at),
url: `https://linux.do/t/${topic.id}`,
mobileUrl: `https://linux.do/t/${topic.id}`,
hot: topic.views || topic.like_count
};
});

return {
...result,
data: list
};
};

1 comment on commit 0fa3108

@stevessrbackup
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

起猛了,看见linux do了,
其实好像discourse支持rss
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Discourse//EN
BEGIN:VEVENT
UID:1736524800000_1737129540000
DTSTAMP:20250110T052057Z
DTSTART:20250110T160000Z
DTEND:20250117T155900Z
DESCRIPTION:https://linux.do/t/topic/321537/1
SUMMARY:社区开放注册
END:VEVENT
END:VCALENDAR

Please sign in to comment.