From 6988df58f12f8bc2b03ccb2755165f9097b3b935 Mon Sep 17 00:00:00 2001 From: imsyy Date: Mon, 24 Jun 2024 16:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E4=B8=8A=E7=9A=84=E4=BB=8A=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router.types.d.ts | 8 ++++++++ src/routes/history.ts | 41 +++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/router.types.d.ts b/src/router.types.d.ts index 5c99f6f..f644399 100644 --- a/src/router.types.d.ts +++ b/src/router.types.d.ts @@ -269,4 +269,12 @@ export type RouterType = { period: string; productId: string; }; + history: { + year: string; + title: string; + link: string; + desc: string; + cover: string; + pic_share: string; + }; }; diff --git a/src/routes/history.ts b/src/routes/history.ts index 83dbdfb..92e0397 100644 --- a/src/routes/history.ts +++ b/src/routes/history.ts @@ -1,4 +1,5 @@ import type { RouterData, ListContext, Options } from "../types.js"; +import type { RouterType } from "../router.types.js"; import { load } from "cheerio"; import { get } from "../utils/getData.js"; import { getCurrentDateTime } from "../utils/getTime.js"; @@ -16,7 +17,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => { month: "月份", day: "日期", }, - link: "https://www.lssjt.com/", + link: "https://baike.baidu.com/calendar", total: data?.length || 0, updateTime, fromCache, @@ -26,26 +27,30 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => { }; const getList = async (options: Options, noCache: boolean) => { const { month, day } = options; - const url = `https://www.lssjt.com/${month}/${day}/`; - const result = await get({ url, noCache }); - const $ = load(result.data); - const listDom = $("li.circler"); - const listData = listDom.toArray().map((item, index) => { - const dom = $(item); - const href = dom.find("a").attr("href"); - return { - id: index, - title: dom.find("a.txt").text().trim() || dom.find("a").attr("title"), - cover: dom.find("img").attr("data-original"), - timestamp: dom.find("div.text span").text().trim() || dom.find("div.t span").text().trim(), - hot: null, - url: href || undefined, - mobileUrl: href || undefined, - }; + const monthStr = month.toString().padStart(2, "0"); + const dayStr = day.toString().padStart(2, "0"); + const url = `https://baike.baidu.com/cms/home/eventsOnHistory/${monthStr}.json`; + const result = await get({ + url, + noCache, + params: { + _: new Date().getTime(), + }, }); + const list = result.data[monthStr][monthStr + dayStr]; return { fromCache: result.fromCache, updateTime: result.updateTime, - data: listData, + data: list.map((v: RouterType["history"], index: number) => ({ + id: index, + title: load(v.title).text().trim(), + cover: v.cover ? v.pic_share : null || null, + desc: load(v.desc).text().trim(), + year: v.year, + timestamp: null, + hot: null, + url: v.link, + mobileUrl: v.link, + })), }; };