mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-08 16:06:13 +02:00
fix: hopefully fix for #334
This commit is contained in:
committed by
Jean-Philippe Sirois
parent
6b267780b5
commit
b6b295fced
+28
-6
@@ -1,7 +1,29 @@
|
||||
/**
|
||||
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
|
||||
*
|
||||
* See: https://www.gatsbyjs.org/docs/ssr-apis/
|
||||
*/
|
||||
import React from "react"
|
||||
|
||||
// You can delete this file if you're not using it
|
||||
const ThemeScript = () => {
|
||||
const themeScript = `
|
||||
(function() {
|
||||
function getInitialTheme() {
|
||||
const userSetTheme = window.localStorage.getItem("theme")
|
||||
const prefersLightTheme = window.matchMedia(
|
||||
"(prefers-color-scheme: light)"
|
||||
)
|
||||
|
||||
if (userSetTheme && userSetTheme !== '"unset"') return userSetTheme
|
||||
else if (prefersLightTheme.matches === true) return "light"
|
||||
else return "dark"
|
||||
}
|
||||
|
||||
document.documentElement.style.setProperty(
|
||||
"--initial-theme",
|
||||
getInitialTheme()
|
||||
)
|
||||
})()
|
||||
`
|
||||
|
||||
return <script dangerouslySetInnerHTML={{ __html: themeScript }} />
|
||||
}
|
||||
|
||||
export const onRenderBody = ({ setPreBodyComponents }) => {
|
||||
setPreBodyComponents(<ThemeScript></ThemeScript>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user