-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
34 lines (30 loc) · 958 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
import { Helmet } from "react-helmet";
// https://github.com/gatsbyjs/gatsby/issues/22206
export function 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(),
]);
}
export function 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);
}