feat: support query theme bootstrap for embeds
This commit is contained in:
@@ -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);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user