feat: 水木社区

This commit is contained in:
imsyy
2025-05-11 00:00:53 +08:00
parent c9ee406372
commit 20a5b537f9
3 changed files with 59 additions and 1 deletions

17
src/router.types.d.ts vendored
View File

@@ -377,4 +377,21 @@ export type RouterType = {
}[]; }[];
}; };
}; };
newsmth: {
firstArticleId: string;
subject: string;
article: {
topicId: string;
postTime: number;
subject: string;
body: string;
account: {
name: string;
};
};
board: {
title: string;
name: string;
};
};
}; };

View File

@@ -27,7 +27,6 @@ const getList = async (noCache: boolean) => {
const post = v.post; const post = v.post;
return { return {
id: post.id, id: post.id,
title: post.title, title: post.title,
desc: post.abstract, desc: post.abstract,
cover: post.cover_url, cover: post.cover_url,

42
src/routes/newsmth.ts Normal file
View File

@@ -0,0 +1,42 @@
import type { RouterData } from "../types.js";
import type { RouterType } from "../router.types.js";
import { get } from "../utils/getData.js";
import { getTime } from "../utils/getTime.js";
export const handleRoute = async (_: undefined, noCache: boolean) => {
const listData = await getList(noCache);
const routeData: RouterData = {
name: "newsmth",
title: "水木社区",
type: "热门话题",
description: "水木社区是一个源于清华的高知社群。",
link: "https://www.newsmth.net/",
total: listData.data?.length || 0,
...listData,
};
return routeData;
};
const getList = async (noCache: boolean) => {
const url = `https://wap.newsmth.net/wap/api/hot/global`;
const result = await get({ url, noCache });
const list = result.data?.data?.topics;
return {
...result,
data: list.map((v: RouterType["newsmth"]) => {
const post = v.article;
const url = `https://wap.newsmth.net/article/${post.topicId}?title=${v.board?.title}&from=home`;
return {
id: v.firstArticleId,
title: post.subject,
desc: post.body,
cover: undefined,
author: post?.account?.name,
hot: undefined,
timestamp: getTime(post.postTime),
url,
mobileUrl: url,
};
}),
};
};