spaCy/website/gatsby-browser.js

51 lines
1.9 KiB
JavaScript
Raw Normal View History

import { navigate } from 'gatsby'
import './src/styles/layout.sass'
import Juniper from './src/components/juniper'
2019-02-26 11:25:25 +00:00
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)
}
}