diff --git a/src/router.types.d.ts b/src/router.types.d.ts index a00e232..19bc05f 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -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; + }; + }; }; diff --git a/src/routes/geekpark.ts b/src/routes/geekpark.ts index 0e6cb4e..212c45e 100644 --- a/src/routes/geekpark.ts +++ b/src/routes/geekpark.ts @@ -27,7 +27,6 @@ const getList = async (noCache: boolean) => { const post = v.post; return { id: post.id, - title: post.title, desc: post.abstract, cover: post.cover_url, diff --git a/src/routes/newsmth.ts b/src/routes/newsmth.ts new file mode 100644 index 0000000..622fb43 --- /dev/null +++ b/src/routes/newsmth.ts @@ -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, + }; + }), + }; +};