-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.js
36 lines (35 loc) · 1.1 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const React = require("react")
const fs = require("fs")
exports.onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script
// Theming setup
dangerouslySetInnerHTML={{
__html: `!(function () {
function e(e) {
(window.__theme = e),
(document.documentElement.className = "dark" === e ? "dark" : ""),
window.dispatchEvent(new CustomEvent("theme", { detail: e }));
}
let t, l, ul, h = new Date().getHours();
window.__setPreferredTheme = function (t) {
e(t);
try {
localStorage.setItem("preferred-theme", t);
} catch (e) {}
};
try {
t = localStorage.getItem("preferred-theme");
} catch (e) {}
try {
ul = !!localStorage.getItem("user-location")
if(ul) l = (h > 16 || h < 8) ? "dark" : "light";
} catch (e) {}
let r = window.matchMedia("(prefers-color-scheme: dark)");
e(l || t || (r.matches ? "dark" : "light"));
})();
`,
}}
/>,
])
}