-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
38 lines (34 loc) · 1.12 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 { ThemeProvider } from 'styled-components'
import theme from './static/styles/theme'
import Layout from './src/components/Layout'
import Helmet from 'react-helmet'
import { GlobalStyle } from './src/components/GlobalStyles'
export const wrapRootElement = ({ element }) => {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />
{element}
</ThemeProvider>
)
}
// Pass all props (hence the ...props) to the layout component so it has access to things like pageContext or location
export const wrapPageElement = ({ element, props }) => (
<Layout {...props}>{element}</Layout>
)
export const onRenderBody = (
{ setHeadComponents, setHtmlAttributes, setBodyAttributes },
pluginOptions
) => {
const helmet = Helmet.renderStatic()
setHtmlAttributes(helmet.htmlAttributes.toComponent())
setBodyAttributes(helmet.bodyAttributes.toComponent())
setHeadComponents([
helmet.title.toComponent('Testing new title'),
helmet.link.toComponent(),
helmet.meta.toComponent(),
helmet.noscript.toComponent(),
helmet.script.toComponent(),
helmet.style.toComponent()
])
}