From 679fdab87e3bb4b8135d085b60d357b02136dd09 Mon Sep 17 00:00:00 2001 From: imsyy Date: Thu, 16 May 2024 18:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E=20?= =?UTF-8?q?=E8=99=8E=E5=97=85=20&=20=E7=88=B1=E8=8C=83=E5=84=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ src/index.ts | 6 +++--- src/router.types.ts | 17 +++++++++++++++ src/routes/huxiu.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++ src/routes/ifanr.ts | 37 ++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 src/routes/huxiu.ts create mode 100644 src/routes/ifanr.ts diff --git a/README.md b/README.md index 00463f7..75dbdbb 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ | 稀土掘金 | 热榜 | juejin | 🟢 | | 腾讯新闻 | 热点榜 | qq-news | 🟢 | | 网易新闻 | 热点榜 | netease-news | 🟢 | +| 虎嗅 | 24小时 | huxiu | 🟢 | +| 爱范儿 | 快讯 | ifanr | 🟢 | | 英雄联盟 | 更新公告 | lol | 🟢 | | 原神 | 最新消息 | genshin | 🟢 | | 崩坏3 | 最新动态 | honkai | 🟢 | diff --git a/src/index.ts b/src/index.ts index b15b779..60274fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,13 +3,13 @@ import { config } from "./config.js"; import logger from "./utils/logger.js"; import app from "./app.js"; -logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`); -logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`); - // 启动服务器 const server = serve({ fetch: app.fetch, port: config.PORT, }); +logger.info(`🔥 DailyHot API 成功在端口 ${config.PORT} 上运行`); +logger.info(`🔗 Local: 👉 http://localhost:${config.PORT}`); + export default server; diff --git a/src/router.types.ts b/src/router.types.ts index ff9bd21..40f60d9 100644 --- a/src/router.types.ts +++ b/src/router.types.ts @@ -214,4 +214,21 @@ export type RouterType = { url: string; pic: string; }; + huxiu: { + object_id: number; + content: string; + url: string; + user_info: { + username: string; + }; + }; + ifanr: { + buzz_original_url: string; + id: number; + post_content: string; + post_id: number; + post_title: string; + like_count: number; + comment_count: number; + }; }; diff --git a/src/routes/huxiu.ts b/src/routes/huxiu.ts new file mode 100644 index 0000000..c953225 --- /dev/null +++ b/src/routes/huxiu.ts @@ -0,0 +1,51 @@ +import type { RouterData } from "../types.js"; +import type { RouterType } from "../router.types.js"; +import { get } from "../utils/getData.js"; + +export const handleRoute = async (_: undefined, noCache: boolean) => { + const { fromCache, data, updateTime } = await getList(noCache); + const routeData: RouterData = { + name: "huxiu", + title: "虎嗅", + type: "24小时", + link: "https://www.huxiu.com/moment/", + total: data?.length || 0, + updateTime, + fromCache, + data, + }; + return routeData; +}; + +// 标题处理 +const titleProcessing = (text: string) => { + const paragraphs = text.split("

"); + const title = paragraphs.shift().replace(/。$/, ""); + const intro = paragraphs.join("

"); + return { title, intro }; +}; + +const getList = async (noCache: boolean) => { + const url = `https://www.huxiu.com/moment/`; + const result = await get({ + url, + noCache, + }); + // 正则查找 + const pattern = + /