This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
/
gatsby-ssr.js
66 lines (58 loc) · 1.75 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
54
55
56
57
58
59
60
61
62
63
64
65
66
import { JssProvider } from "react-jss";
import { Provider } from "react-redux";
import { renderToString } from "react-dom/server";
import React from "react";
require("dotenv").config();
import getPageContext from "./src/getPageContext";
import createStore from "./src/state/store";
import theme from "./src/styles/theme";
exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString, setHeadComponents }) => {
const pageContext = getPageContext();
const store = createStore();
replaceBodyHTMLString(
renderToString(
<Provider store={store}>
<JssProvider
registry={pageContext.sheetsRegistry}
generateClassName={pageContext.generateClassName}
>
{React.cloneElement(bodyComponent, {
pageContext
})}
</JssProvider>
</Provider>
)
);
setHeadComponents([
<style
type="text/css"
id="server-side-jss"
key="server-side-jss"
dangerouslySetInnerHTML={{ __html: pageContext.sheetsRegistry.toString() }}
/>
]);
};
exports.onRenderBody = ({ setHeadComponents }) => {
return setHeadComponents([]);
};
exports.onRenderBody = ({ setPostBodyComponents }) => {
return setPostBodyComponents([
<script
key={`webfontsloader-setup`}
dangerouslySetInnerHTML={{
__html: `
WebFontConfig = {
google: {
families: ["${theme.base.fonts.styledFamily}:${theme.base.fonts.styledFonts}"]
}
};
(function(d) {
var wf = d.createElement('script'), s = d.scripts[0];
wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
wf.async = true;
s.parentNode.insertBefore(wf, s);
})(document);`
}}
/>
]);
};