-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
37 lines (32 loc) · 1.15 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
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.com/docs/ssr-apis/
*/
// You can delete this file if you're not using it
require('firebase/compat/database');
const ClientOnlyVisibleWrapper =
require('./src/components/ClientOnlyVisibleWrapper').default;
export const onRenderBody = ({ setHeadComponents }) => {
setHeadComponents([
<script
dangerouslySetInnerHTML={{
__html: `
(function() {
let preferredTheme = null;
try {
preferredTheme = localStorage.getItem('preferred-theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
} catch {
console.error('다크, 라이트 모드 정보를 가져올 수 없습니다.');
}
document.documentElement.setAttribute('data-preferred-theme', preferredTheme);
window.__theme = preferredTheme;
})();
`,
}}
/>,
]);
};
export const wrapPageElement = ({ element }) => {
return <ClientOnlyVisibleWrapper>{element}</ClientOnlyVisibleWrapper>;
};