From 058e0b7f8f2637a3284b78b59d2806b33f79e381 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 18 Oct 2019 17:45:34 +0200 Subject: [PATCH] feat: SSR MathJax and Stripe on routes using them (#37388) * feat: SSR MathJax and Stripe on routes using them * refactor: clean up scripts --- client/gatsby-ssr.js | 81 +++++++++++++++++++++++++++++--------- client/src/head/index.js | 4 +- client/src/head/mathjax.js | 9 ----- client/src/head/scripts.js | 3 -- 4 files changed, 64 insertions(+), 33 deletions(-) delete mode 100644 client/src/head/mathjax.js delete mode 100644 client/src/head/scripts.js diff --git a/client/gatsby-ssr.js b/client/gatsby-ssr.js index 9306aa55aa..9e468bc0f8 100644 --- a/client/gatsby-ssr.js +++ b/client/gatsby-ssr.js @@ -17,28 +17,73 @@ wrapRootElement.propTypes = { element: PropTypes.any }; +// TODO: put these in a common utils file. +const mathJaxCdn = { + address: + 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/' + + '2.7.4/MathJax.js?config=TeX-AMS_HTML', + key: 'mathjax', + type: 'text/javascript' +}; + +const stripeScript = { + address: 'https://js.stripe.com/v3/', + id: 'stripe-js', + key: 'stripe-js', + type: 'text/javascript' +}; + +const challengeRE = new RegExp('/learn/[^/]+/[^/]+/[^/]+/?$'); +const donateRE = new RegExp('/donate/?$'); + export const wrapPageElement = layoutSelector; -export const onRenderBody = ({ setHeadComponents, setPostBodyComponents }) => { +export const onRenderBody = ({ + pathname, + setHeadComponents, + setPostBodyComponents +}) => { setHeadComponents([...headComponents]); - setPostBodyComponents( - [ + const scripts = [ +