feat: add dark mode support with theme toggle

This commit is contained in:
张翔
2026-02-13 15:17:42 +08:00
parent 34c96c119d
commit 8175c2f035
8 changed files with 1761 additions and 241 deletions
+17 -3
View File
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono, Noto_Sans_SC } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@/contexts/theme-context";
const geistSans = Geist({
variable: "--font-geist-sans",
@@ -57,17 +58,30 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang="zh-CN" className="scroll-smooth">
<html lang="zh-CN" className="scroll-smooth" suppressHydrationWarning>
<head>
{/* Favicon */}
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="apple-touch-icon" href="/favicon.svg" />
<script
dangerouslySetInnerHTML={{
__html: `
try {
const theme = localStorage.getItem('ruixin-theme') || 'system';
if (theme === 'dark' || (theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
}
} catch {}
`,
}}
/>
</head>
<body
className={`${geistSans.variable} ${geistMono.variable} ${notoSansSC.variable} font-sans antialiased`}
style={{ fontFamily: "'Noto Sans SC', 'Geist', -apple-system, BlinkMacSystemFont, sans-serif" }}
>
{children}
<ThemeProvider>
{children}
</ThemeProvider>
</body>
</html>
);