-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
73 lines (71 loc) · 1.89 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
67
68
69
70
71
72
73
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
const React = require('react')
const { dom } = require('@fortawesome/fontawesome-svg-core')
export const onPreRenderHTML = ({
getHeadComponents,
replaceHeadComponents,
getPreBodyComponents,
replacePreBodyComponents,
getPostBodyComponents,
replacePostBodyComponents
}) => {
const headComponents = getHeadComponents()
headComponents.push(
<style
id="fontawesome-ssr"
key="fontawesome-ssr"
dangerouslySetInnerHTML={{ __html: dom.css() }}
/>
)
headComponents.push(
<script
key="mathjax"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"
async={true}
/>
)
headComponents.push(
<meta
key="google-search-console"
name="google-site-verification"
content="vfBieEK9GH8ZUhz0vrwxJDaNOXdq8ztAv21tboXSCVI"
/>
)
headComponents.unshift(
<script
key="prefers-dark-mode"
dangerouslySetInnerHTML={{
__html: "(localStorage.getItem('userNightMode') === 'true' || localStorage.getItem('userNightMode') !== 'false' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) && document.documentElement.classList.toggle('nightly', true)"
}}
/>
)
headComponents.unshift(
<style
key="dark-mode-super"
dangerouslySetInnerHTML={{
__html: `
html.nightly, html.nightly > body {
background: #222;
color: #cecece;
}`
}}
/>
)
replaceHeadComponents(headComponents)
const postBodyComponents = getPostBodyComponents()
postBodyComponents.push(
<kokoro-provider>
<kokoro-player
lang="zh_Hans"
top="100"
left="0"
mobileDefaultSide="right"
/>
</kokoro-provider>
)
replacePostBodyComponents(postBodyComponents)
}