forked from the-programmers-hangout/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hopefully fix for the-programmers-hangout#334
- Loading branch information
1 parent
70762f0
commit eef5d17
Showing
2 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters