feat: 更新默认站点名称以更清晰地反映错误状态,优化合并逻辑以支持对象递归合并

This commit is contained in:
2025-09-26 00:31:45 +08:00
parent 51c6718fc9
commit 2d1dc2b055
2 changed files with 6 additions and 4 deletions

View File

@ -72,8 +72,10 @@ export default async function RootLayout({
const siteInfo = await getSiteInfo().then(res => res.data).catch(() => fallbackSiteInfo);
const colorSchemes = siteInfo?.colorSchemes ? siteInfo.colorSchemes : fallbackSiteInfo.colorSchemes;
console.log(siteInfo)
return (
<html lang={await getFirstLocale() || "en"} className="h-full" data-user-color={(colorSchemes).includes(user?.preferredColor || "") ? user?.preferredColor : "blue"}>
<html lang={await getFirstLocale() || "en"} className="h-full" data-user-color={colorSchemes.includes(user?.preferredColor || "") ? user?.preferredColor : "blue"}>
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>

View File

@ -34,7 +34,7 @@ export type SiteInfo = {
export const fallbackSiteInfo: SiteInfo = {
colorSchemes: ["blue", "green", "orange", "red", "rose", "violet", "yellow"],
metadata: {
name: "Failed to Fetch Name",
name: "Failed to Fetch",
icon: "",
description: "Failed to fetch site info from server.",
},
@ -87,8 +87,8 @@ function mergeWithFallback<T extends Record<string, unknown>>(initial: T, fallba
typeof fallbackValue === 'object' &&
!Array.isArray(fallbackValue)
) {
// 如果都是对象(非数组),也不要递归合并
result[key] = { ...initialValue, ...fallbackValue };
// 如果都是对象(非数组),递归合并
result[key] = mergeWithFallback(initialValue as Record<string, unknown>, fallbackValue as Record<string, unknown>) as T[typeof key];
}
// 否则保持 initial 的值不变
}