This commit is contained in:
2026-01-01 21:59:28 +08:00
parent 2eba888094
commit 1d888e9af0
38 changed files with 449 additions and 2469 deletions

View File

@@ -24,3 +24,29 @@ export function formatDate(dateString: string): string {
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
/**
* Gets a random 404 image from the /public/404/ directory
* @returns A random image path from /public/404/
*/
export function getRandomFallbackImage(): string {
const fallbackImages: string[] = [
"/404/1.webp",
"/404/2.webp",
"/404/3.webp",
"/404/4.webp",
"/404/5.webp",
"/404/6.webp",
"/404/7.webp",
"/404/8.webp",
"/404/9.webp",
];
if (import.meta.server) {
// 在服务器端返回第一张图片以保证 SSR 一致性
return fallbackImages[0]!;
}
const randomIndex = Math.floor(Math.random() * fallbackImages.length);
return fallbackImages[randomIndex]!;
}