feat: support query theme bootstrap for embeds

This commit is contained in:
2026-04-02 20:41:18 +08:00
parent 83071a4b76
commit 6e55bc02b7
4 changed files with 87 additions and 9 deletions

View File

@@ -26,10 +26,22 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang="zh" className={`${outfit.variable} ${jetbrains.variable} h-full antialiased dark`} suppressHydrationWarning>
<html lang="zh" className={`${outfit.variable} ${jetbrains.variable} h-full antialiased`} suppressHydrationWarning>
<head>
<script dangerouslySetInnerHTML={{ __html: `
(function(){
var q=null;
try{
var rawTheme=new URLSearchParams(window.location.search).get('theme');
if(rawTheme){
rawTheme=rawTheme.toLowerCase();
if(rawTheme==='light'||rawTheme==='dark'){
q=rawTheme;
}else if(rawTheme==='auto'||rawTheme==='system'){
q=window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light';
}
}
}catch(e){}
var parentTheme=null;
try{
if(window.self!==window.top){
@@ -38,7 +50,8 @@ export default function RootLayout({
}
}catch(e){}
var t=localStorage.getItem('theme')||'system';
var r=parentTheme||(t==='system'?window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light':t);
var r=q||parentTheme||(t==='system'?window.matchMedia('(prefers-color-scheme:dark)').matches?'dark':'light':t);
document.documentElement.classList.remove('light','dark');
document.documentElement.classList.add(r);
document.documentElement.setAttribute('data-theme',r);
})();