mirror of
https://github.com/imsyy/DailyHotApi.git
synced 2026-01-12 13:14:55 +08:00
🐞 fix: 修复历史上的今天
This commit is contained in:
8
src/router.types.d.ts
vendored
8
src/router.types.d.ts
vendored
@@ -269,4 +269,12 @@ export type RouterType = {
|
|||||||
period: string;
|
period: string;
|
||||||
productId: string;
|
productId: string;
|
||||||
};
|
};
|
||||||
|
history: {
|
||||||
|
year: string;
|
||||||
|
title: string;
|
||||||
|
link: string;
|
||||||
|
desc: string;
|
||||||
|
cover: string;
|
||||||
|
pic_share: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { RouterData, ListContext, Options } from "../types.js";
|
import type { RouterData, ListContext, Options } from "../types.js";
|
||||||
|
import type { RouterType } from "../router.types.js";
|
||||||
import { load } from "cheerio";
|
import { load } from "cheerio";
|
||||||
import { get } from "../utils/getData.js";
|
import { get } from "../utils/getData.js";
|
||||||
import { getCurrentDateTime } from "../utils/getTime.js";
|
import { getCurrentDateTime } from "../utils/getTime.js";
|
||||||
@@ -16,7 +17,7 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
month: "月份",
|
month: "月份",
|
||||||
day: "日期",
|
day: "日期",
|
||||||
},
|
},
|
||||||
link: "https://www.lssjt.com/",
|
link: "https://baike.baidu.com/calendar",
|
||||||
total: data?.length || 0,
|
total: data?.length || 0,
|
||||||
updateTime,
|
updateTime,
|
||||||
fromCache,
|
fromCache,
|
||||||
@@ -26,26 +27,30 @@ export const handleRoute = async (c: ListContext, noCache: boolean) => {
|
|||||||
};
|
};
|
||||||
const getList = async (options: Options, noCache: boolean) => {
|
const getList = async (options: Options, noCache: boolean) => {
|
||||||
const { month, day } = options;
|
const { month, day } = options;
|
||||||
const url = `https://www.lssjt.com/${month}/${day}/`;
|
const monthStr = month.toString().padStart(2, "0");
|
||||||
const result = await get({ url, noCache });
|
const dayStr = day.toString().padStart(2, "0");
|
||||||
const $ = load(result.data);
|
const url = `https://baike.baidu.com/cms/home/eventsOnHistory/${monthStr}.json`;
|
||||||
const listDom = $("li.circler");
|
const result = await get({
|
||||||
const listData = listDom.toArray().map((item, index) => {
|
url,
|
||||||
const dom = $(item);
|
noCache,
|
||||||
const href = dom.find("a").attr("href");
|
params: {
|
||||||
return {
|
_: new Date().getTime(),
|
||||||
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 list = result.data[monthStr][monthStr + dayStr];
|
||||||
return {
|
return {
|
||||||
fromCache: result.fromCache,
|
fromCache: result.fromCache,
|
||||||
updateTime: result.updateTime,
|
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,
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user