File tree Expand file tree Collapse file tree
docs/ai/llm-basics/pytorch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use client" ;
2+ import { useEffect , useState } from "react" ;
3+
4+ export default function DarkModeToggle ( ) {
5+ const [ isDark , setIsDark ] = useState ( false ) ;
6+
7+ // On mount, check localStorage or system preference
8+ useEffect ( ( ) => {
9+ const saved = localStorage . getItem ( "theme" ) ;
10+ if (
11+ saved === "dark" ||
12+ ( ! saved && window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches )
13+ ) {
14+ setIsDark ( true ) ;
15+ document . documentElement . classList . add ( "dark" ) ;
16+ } else {
17+ setIsDark ( false ) ;
18+ document . documentElement . classList . remove ( "dark" ) ;
19+ }
20+ } , [ ] ) ;
21+
22+ // Toggle handler
23+ const toggle = ( ) => {
24+ const next = ! isDark ;
25+ setIsDark ( next ) ;
26+ if ( next ) {
27+ document . documentElement . classList . add ( "dark" ) ;
28+ localStorage . setItem ( "theme" , "dark" ) ;
29+ } else {
30+ document . documentElement . classList . remove ( "dark" ) ;
31+ localStorage . setItem ( "theme" , "light" ) ;
32+ }
33+ } ;
34+
35+ return (
36+ < button
37+ aria-label = "Toggle dark mode"
38+ onClick = { toggle }
39+ style = { {
40+ position : "fixed" ,
41+ top : 16 ,
42+ right : 16 ,
43+ zIndex : 100 ,
44+ background : "none" ,
45+ border : "none" ,
46+ cursor : "pointer" ,
47+ fontSize : 24 ,
48+ color : isDark ? "#ededed" : "#171717" ,
49+ transition : "color 0.2s" ,
50+ } }
51+ >
52+ { isDark ? "🌙" : "☀️" }
53+ </ button >
54+ ) ;
55+ }
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -35,8 +35,8 @@ PyTorch是现代深度学习最重要的框架之一,特别在研究和大模
3535## 核心概念
3636
3737- ** 张量 (Tensor)** :PyTorch 的核心数据结构,支持 GPU 加速的多维数组
38- ![ ] ( /images/word /word-img-01.png)
39- ![ ] ( /images/word /word-img-02.png)
38+ ![ ] ( ./index.assets /word-img-01.png)
39+ ![ ] ( ./index.assets /word-img-02.png)
4040- ** 自动梯度 (Autograd)** :动态计算图与自动微分系统
4141- ** 神经网络模块 (nn.Module)** :模块化构建神经网络
4242- ** 训练循环** :优化器、损失函数、学习率调度等
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { RootProvider } from "fumadocs-ui/provider";
44import Script from "next/script" ;
55import "./globals.css" ;
66
7+ import DarkModeToggle from "@/app/components/DarkModeToggle" ;
8+
79const geistSans = localFont ( {
810 src : "./fonts/GeistVF.woff" ,
911 variable : "--font-geist-sans" ,
@@ -30,6 +32,7 @@ export default function RootLayout({
3032 < body
3133 className = { `${ geistSans . variable } ${ geistMono . variable } antialiased` }
3234 >
35+ < DarkModeToggle />
3336 < RootProvider > { children } </ RootProvider >
3437 < Script
3538 src = "https://www.googletagmanager.com/gtag/js?id=G-ED4GVN8YVW"
You can’t perform that action at this time.
0 commit comments