-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
66 lines (51 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
const React = require("react")
exports.onRenderBody = ({ setPreBodyComponents, setHeadComponents }) => {
setHeadComponents([
<script data-ad-client="ca-pub-1149332608171839" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" />
])
setPreBodyComponents([
React.createElement("script", {
dangerouslySetInnerHTML: {
__html: `var vglnk = {key: 'de3d3757987fc8a894399a9c82c60612'};
(function(d, t) {
var s = d.createElement(t);
s.type = 'text/javascript';
s.async = true;
s.src = '//cdn.viglink.com/api/vglnk.js';
var r = d.getElementsByTagName(t)[0];
r.parentNode.insertBefore(s, r);
}(document, 'script'));`
}
}),
React.createElement("script", {
dangerouslySetInnerHTML: {
__html: `
(() => {
window.__onThemeChange = function() {};
function setTheme(newTheme) {
window.__theme = newTheme;
preferredTheme = newTheme;
document.body.className = 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.addListener(e => {
window.__setPreferredTheme(e.matches ? 'light' : 'dark')
})
setTheme(preferredTheme || (darkQuery.matches ? 'light' : 'dark'))
})()
`,
},
}),
])
}