-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
34 lines (30 loc) · 928 Bytes
/
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
const React = require("react")
const { Helmet } = require("react-helmet")
exports.onRenderBody = (
{ setHeadComponents, setHtmlAttributes, setBodyAttributes },
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(),
])
}
exports.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)
}