From c9ee40637220966dccaf22204d72e5d92b3d3b88 Mon Sep 17 00:00:00 2001 From: imsyy Date: Mon, 9 Dec 2024 18:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E6=9E=81=E5=AE=A2=E5=85=AC=E5=9B=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router.types.d.ts | 14 ++++++++++++++ src/routes/geekpark.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/routes/geekpark.ts diff --git a/src/router.types.d.ts b/src/router.types.d.ts index d4278d82..a00e232f 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -363,4 +363,18 @@ export type RouterType = { created_at: number; type: number; }; + geekpark: { + post: { + id: number; + nickname: string; + title: string; + abstract: string; + cover_url: string; + views: number; + published_timestamp: number; + authors: { + nickname: string; + }[]; + }; + }; }; diff --git a/src/routes/geekpark.ts b/src/routes/geekpark.ts new file mode 100644 index 00000000..0e6cb4e9 --- /dev/null +++ b/src/routes/geekpark.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: "geekpark", + title: "极客公园", + type: "热门文章", + description: "极客公园聚焦互联网领域,跟踪新鲜的科技新闻动态,关注极具创新精神的科技产品。", + link: "https://www.geekpark.net/", + total: listData.data?.length || 0, + ...listData, + }; + return routeData; +}; + +const getList = async (noCache: boolean) => { + const url = `https://mainssl.geekpark.net/api/v2`; + const result = await get({ url, noCache }); + const list = result.data?.homepage_posts; + return { + ...result, + data: list.map((v: RouterType["geekpark"]) => { + const post = v.post; + return { + id: post.id, + + title: post.title, + desc: post.abstract, + cover: post.cover_url, + author: post?.authors?.[0]?.nickname, + hot: post.views, + timestamp: getTime(post.published_timestamp), + url: `https://www.geekpark.net/news/${post.id}`, + mobileUrl: `https://www.geekpark.net/news/${post.id}`, + }; + }), + }; +};