1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-25 19:34:48 +01:00
blog/gatsby-ssr.tsx

27 lines
706 B
TypeScript
Raw Normal View History

2022-11-17 19:29:27 +01:00
import React from 'react'
import { GatsbySSR } from 'gatsby'
2022-11-17 19:29:27 +01:00
import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from './src/helpers/umami'
2023-01-29 22:58:19 +01:00
import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
export const wrapPageElement: GatsbySSR['wrapPageElement'] =
wrapPageElementWithLayout
2022-11-17 19:29:27 +01:00
2022-11-19 17:31:07 +01:00
export const onRenderBody = ({ setPostBodyComponents, setHtmlAttributes }) => {
2022-11-19 22:01:53 +01:00
setHtmlAttributes({ lang: 'en' })
2022-11-17 19:29:27 +01:00
const isEnabled = process.env.NODE_ENV === 'production'
if (!isEnabled) {
return null
}
2022-11-19 17:31:07 +01:00
const umamiOptions = {
2022-11-17 19:29:27 +01:00
src: UMAMI_SCRIPT_URL,
'data-website-id': UMAMI_WEBSITE_ID
}
2022-11-19 17:31:07 +01:00
setPostBodyComponents([
<script key="umami-script" async defer {...umamiOptions} />
2022-11-17 19:29:27 +01:00
])
}