mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 05:04:56 +08:00
Merge branch 'master' of github.com:HelTi/DailyHotApi
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -25,4 +25,5 @@ dist
|
||||
|
||||
package-lock.json
|
||||
# Sentry Config File
|
||||
.env.sentry-build-plugin
|
||||
.env.sentry-build-plugin
|
||||
.nvmrc
|
||||
|
||||
@@ -56,6 +56,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",
|
||||
|
||||
8
src/router.types.d.ts
vendored
8
src/router.types.d.ts
vendored
@@ -377,4 +377,12 @@ export type RouterType = {
|
||||
}[];
|
||||
};
|
||||
};
|
||||
linuxdo: {
|
||||
id: string;
|
||||
title: string;
|
||||
url: string;
|
||||
author: string;
|
||||
desc: string;
|
||||
timestamp: string;
|
||||
};
|
||||
};
|
||||
|
||||
57
src/routes/linuxdo.ts
Normal file
57
src/routes/linuxdo.ts
Normal file
@@ -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
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user