-
Notifications
You must be signed in to change notification settings - Fork 4
/
gatsby-ssr.js
57 lines (48 loc) · 1.61 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const React = require('react');
exports.onRenderBody = ({ setHeadComponents, setPreBodyComponents }) => {
setHeadComponents([
<link
rel="stylesheet"
href="./pretendardvariable-dynamic-subset.css"
key="pretendardVariableFont"
/>,
<link
rel="stylesheet"
href="./pretendard-subset.css"
key="pretendardFont"
/>,
]);
setPreBodyComponents([
React.createElement('script', {
dangerouslySetInnerHTML: {
__html: `
(() => {
window.__onThemeChange = function() {};
function setTheme(newTheme) {
window.__theme = newTheme;
preferredTheme = newTheme;
document.body.className = newTheme;
document.body.dataset.theme = newTheme;
window.__onThemeChange(newTheme);
}
let preferredTheme
try {
preferredTheme = localStorage.getItem('theme')
} catch (err) {}
window.__setPreferredTheme = newTheme => {
setTheme(newTheme)
try {
localStorage.setItem('theme', newTheme)
} catch (err) {}
}
let darkQuery = window.matchMedia('(prefers-color-scheme: dark)')
darkQuery.addEventListener('change', e => {
window.__setPreferredTheme(e.matches ? 'dark' : 'light')
})
setTheme(preferredTheme || (darkQuery.matches ? 'dark' : 'light'))
})()
`,
},
}),
]);
};