-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-ssr.js
35 lines (31 loc) · 945 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
35
import { renderToString } from 'react-dom/server';
import Helmet from 'react-helmet';
import { ServerStyleSheet } from 'styled-components';
export const replaceRenderer = ({
bodyComponent,
replaceBodyHTMLString,
setHeadComponents
}) => {
const sheet = new ServerStyleSheet();
const body = renderToString(sheet.collectStyles(bodyComponent));
replaceBodyHTMLString(body);
setHeadComponents([sheet.getStyleElement()]);
return;
};
export const 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(),
]);
};