-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-ssr.js
46 lines (42 loc) · 919 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
36
37
38
39
40
41
42
43
44
45
46
const React = require("react");
let warning = false;
exports.onRenderBody = ({ setPostBodyComponents }, options = {}) => {
options = Object.assign(
{
apiKey: process.env.SNIPC_PUBLIC,
autopop: false,
js: "https://cdn.snipcart.com/themes/v3.2.1/default/snipcart.js",
styles: "https://cdn.snipcart.com/themes/v3.2.1/default/snipcart.css"
},
options
);
if (!options.apiKey) {
if (!warning) {
warning = true;
console.log("No Snipcart API key found");
}
return;
}
const components = [
<script
key="snipcartJs"
src={options.js}
id="snipcart"
data-api-key={options.apiKey}
data-autopop="false"
data-currency="eur"
data-config-modal-style="side"
></script>
];
if (options.styles) {
components.push(
<link
key="snipcartStyle"
href={options.styles}
type="text/css"
rel="stylesheet"
/>
);
}
return setPostBodyComponents(components);
};