-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-ssr.js
53 lines (45 loc) · 1.45 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
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
// You can delete this file if you're not using it
import React from 'react'
import Segment from "decentraland-gatsby/dist/components/Development/Segment"
import Rollbar from "decentraland-gatsby/dist/components/Development/Rollbar"
export { wrapPageElement, wrapRootElement } from './gatsby-browser'
/**
* @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#onPreRenderHTML
*/
export function onPreRenderHTML({
pathname,
getHeadComponents,
replaceHeadComponents,
getPreBodyComponents,
replacePreBodyComponents,
getPostBodyComponents,
replacePostBodyComponents
}, pluginOptions) {
const headComponents = getHeadComponents()
.map((component) => {
if (component.type !== 'style' || !component.props['data-href']) {
return component
}
return <link rel="stylesheet" id={component.props.id} href={component.props['data-href']} />
})
const postBodyComponents = [
...getPostBodyComponents(),
]
if (process.env.GATSBY_SEGMENT_KEY) {
postBodyComponents.push(
<Segment key="segment" />
)
}
if (process.env.GATSBY_ROLLBAR_TOKEN) {
postBodyComponents.push(
<Rollbar key="rollbar" src="https://decentraland.org/js/libs/rollbar.js/2.22.0/rollbar.min.js" />
)
}
replaceHeadComponents(headComponents)
replacePostBodyComponents(postBodyComponents)
}