-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-ssr.js
38 lines (33 loc) · 1.06 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
import React from 'react'
import { Helmet } from 'react-helmet'
export const onRenderBody = ({ setHeadComponents, setHtmlAttributes, setBodyAttributes, setPostBodyComponents }, pluginOptions) => {
const helmet = Helmet.renderStatic()
setHtmlAttributes(helmet.htmlAttributes.toComponent())
setBodyAttributes(helmet.bodyAttributes.toComponent())
setHeadComponents([
helmet.title.toComponent(),
helmet.link.toComponent(),
helmet.meta.toComponent(),
helmet.noscript.toComponent(),
helmet.script.toComponent(),
helmet.style.toComponent(),
])
setPostBodyComponents([
<script
key="https://www.youtube.com/iframe_api"
src="https://www.youtube.com/iframe_api"
/>
])
}
export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents()
headComponents.sort((x, y) => {
if (x.props && x.props["data-react-helmet"]) {
return -1
} else if (y.props && y.props["data-react-helmet"]) {
return 1
}
return 0
})
replaceHeadComponents(headComponents)
}