forked from apollographql/gatsby-theme-apollo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-ssr.js
76 lines (67 loc) · 1.7 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
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import { CloudinaryContext } from 'cloudinary-react'
import PageLayout from './src/components/page-layout';
import WithGuideCSS from './src/components/with-guide-css';
export const onRenderBody = ({setPostBodyComponents, setHeadComponents}, {ffWidgetId}) => {
if (ffWidgetId) {
setHeadComponents([
<script
key="feedback"
dangerouslySetInnerHTML={{
__html: `
var ffWidgetId = '${ffWidgetId}';
var ffWidgetScript = document.createElement("script");
function loadFF() {
ffWidgetScript.type = "text/javascript";
ffWidgetScript.src = 'https://freddyfeedback.com/widget/freddyfeedback.js';
document.head.appendChild(ffWidgetScript);
}
let delay = 1000
if (document.location.pathname === '/') {
delay = 10 * 1000
}
setTimeout(loadFF, delay);
`,
}}
/>
]);
}
setPostBodyComponents([
React.createElement('script', {
key: 'docsearch',
src:
'https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js'
})
]);
};
const NO_LAYOUT_PATHS = [
'/',
'/welcome/',
'/tshirt/'
]
const NO_LAYOUT_PREFIXES = [
'/paypal',
'/unsubscribe',
]
const noLayout = (path) =>
!path ||
NO_LAYOUT_PATHS.includes(path) ||
NO_LAYOUT_PREFIXES.some((prefix) => path.startsWith(prefix))
export const wrapPageElement = (
{element, props}, // eslint-disable-line react/prop-types
pluginOptions
) => {
const page = (
<CloudinaryContext cloudName="graphql">
{element}
</CloudinaryContext>
)
if (noLayout(props.location.pathname)) {
return <WithGuideCSS>{page}</WithGuideCSS>
}
return (
<PageLayout {...props} pluginOptions={pluginOptions}>
{page}
</PageLayout>
)
}