-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
40 lines (36 loc) · 1.04 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
/*eslint-disable react/prop-types*/
import React, { createElement } from 'react'
import { Location } from '@reach/router'
import ThemeContext from '@components/themeContext'
import Wrapper from '@components/wrapper'
export const wrapPageElement = ({ element, props }) => {
return (
<Location>
{({ location }) => (
<Wrapper location={location} {...props}>
{element}
</Wrapper>
)}
</Location>
)
}
export const wrapRootElement = ({ element }) => {
return <ThemeContext>{element}</ThemeContext>
}
const noflash = `(function() { try {
var mode = localStorage.getItem('elgueymk-theme-mode');
if (!mode) return;
if (window.matchMedia('(prefers-color-scheme: light)').matches) {
document.body.classList.add('is-light');
return;
}
document.body.classList.add('is-' + mode);
} catch (e) {} })();`
export const onRenderBody = ({ setPreBodyComponents }) => {
const script = createElement('script', {
dangerouslySetInnerHTML: {
__html: noflash,
},
})
setPreBodyComponents([script])
}