-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.tsx
30 lines (25 loc) · 922 Bytes
/
gatsby-ssr.tsx
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
import * as React from 'react';
export const onRenderBody = ({ setPreBodyComponents }) => {
const script = `
const savedTheme = localStorage.getItem('maxkim-blog-theme');
const theme = savedTheme || 'light';
window.__theme = theme;
window.__setTheme = (newTheme) => {
document.body.setAttribute("data-theme", newTheme);
localStorage.setItem('maxkim-blog-theme', newTheme);
};
window.__setTheme(theme);
`;
setPreBodyComponents(<script dangerouslySetInnerHTML={{ __html: script }} />);
setPreBodyComponents(
<script
async={true}
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5727170943665894"
crossOrigin="anonymous"
></script>
);
};
export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents();
replaceHeadComponents(headComponents);
};