forked from explosion/spaCy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
50 lines (45 loc) · 1.92 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
44
45
46
47
48
49
50
import { navigate } from 'gatsby'
import './src/styles/layout.sass'
import Juniper from './src/components/juniper'
import 'intersection-observer'
// Workaround to rewrite anchor links
const clientSideRewrites = {
'/usage/linguistic-features/#rule-based-matching': '/usage/rule-based-matching',
}
/* eslint-disable */
import HKGroteskSemiBoldWOFF from './src/fonts/hkgrotesk-semibold.woff'
import HKGroteskSemiBoldWOFF2 from './src/fonts/hkgrotesk-semibold.woff2'
import HKGroteskSemiBoldItalicWOFF from './src/fonts/hkgrotesk-semibolditalic.woff'
import HKGroteskSemiBoldItalicWOFF2 from './src/fonts/hkgrotesk-semibolditalic.woff2'
import HKGroteskBoldWOFF from './src/fonts/hkgrotesk-bold.woff'
import HKGroteskBoldWOFF2 from './src/fonts/hkgrotesk-bold.woff2'
import HKGroteskBoldItalicWOFF from './src/fonts/hkgrotesk-bolditalic.woff'
import HKGroteskBoldItalicWOFF2 from './src/fonts/hkgrotesk-bolditalic.woff2'
/* eslint-enable */
export const onInitialClientRender = () => {
// Importing Juniper in the component currently causes various problems
// because of the global window reference in its dependencies. So this
// is kinda hacky at the moment.
window.Juniper = Juniper
}
export const onRouteUpdate = ({ location }) => {
window.dispatchEvent(new Event('resize')) // for progress
window.dispatchEvent(new Event('scroll')) // for progress
if (location.hash) {
// Client-side rewrites
const rewrite = clientSideRewrites[location.pathname + location.hash]
if (rewrite) {
navigate(rewrite)
return
}
setTimeout(() => {
const el = document.querySelector(`${location.hash}`)
if (el) {
// Navigate to targeted element
el.scrollIntoView()
// Force recomputing :target pseudo class with pushState/popState
window.location.hash = location.hash
}
}, 0)
}
}