forked from PostHog/posthog.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
43 lines (40 loc) · 1.5 KB
/
gatsby-browser.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
/**
* Implement Gatsby's Browser APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/
import React from 'react'
import { initKea, wrapElement } from './kea'
import './src/styles/global.css'
import HandbookLayout from './src/templates/Handbook'
import Product from './src/templates/Product'
import SqueakTopic from './src/templates/SqueakTopic'
import Job from './src/templates/Job'
initKea(false)
export const wrapRootElement = wrapElement
export const onRouteUpdate = ({ location, prevLocation }) => {
// This is checked and set on initial load in the body script set in gatsby-ssr.js
// Checking for prevLocation prevents this from happening twice
if (typeof window !== 'undefined' && prevLocation) {
var slug = location.pathname.substring(1)
var theme = /^handbook|^docs|^blog|^integrations|^tutorials|^questions|^manual|^using-posthog/.test(slug)
? window.__theme
: 'light'
document.body.className = theme
}
}
export const wrapPageElement = ({ element, props }) => {
const slug = props.location.pathname.substring(1)
return /^handbook|^docs\/(?!api)|^manual/.test(slug) &&
!['docs/api/post-only-endpoints', 'docs/api/user'].includes(slug) ? (
<HandbookLayout {...props} />
) : /^product\//.test(slug) ? (
<Product {...props} />
) : /^questions\//.test(slug) ? (
<SqueakTopic {...props} />
) : /^careers\//.test(slug) ? (
<Job {...props} />
) : (
element
)
}