1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-30 21:52:05 +02:00
blog/gatsby-ssr.tsx

26 lines
705 B
TypeScript
Raw Normal View History

2022-11-17 19:29:27 +01:00
import React from 'react'
import { GatsbySSR } from 'gatsby'
import wrapPageElementWithLayout from './src/helpers/wrapPageElement'
2022-11-17 19:29:27 +01:00
import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from './src/helpers/umami'
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-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
setHtmlAttributes({ lang: 'en' })
setPostBodyComponents([
<script key="umami-script" async defer {...umamiOptions} />
2022-11-17 19:29:27 +01:00
])
}