2019-11-08 03:40:20 +01:00
|
|
|
require("prismjs/themes/prism-okaidia.css");
|
|
|
|
require("./src/theme/assets/scss/theme.scss");
|
2019-11-14 23:40:23 +01:00
|
|
|
require('./src/theme/assets/fontawesome/css/all.css');
|
2019-11-08 11:47:42 +01:00
|
|
|
require('./src/theme/assets/search/algolia.css');
|
2019-12-18 23:54:23 +01:00
|
|
|
|
2019-11-08 03:40:20 +01:00
|
|
|
const React = require('react');
|
2019-12-18 23:54:23 +01:00
|
|
|
const Layout = require('./src/components/Layout').default;
|
|
|
|
const NodeProvider = require('./src/components/NodeProvider').default;
|
|
|
|
const smoothScroll = require('smooth-scroll');
|
|
|
|
|
2019-11-08 03:40:20 +01:00
|
|
|
|
2019-11-08 04:53:25 +01:00
|
|
|
if (typeof window !== "undefined") {
|
|
|
|
smoothScroll('a[href*="#"]')
|
|
|
|
}
|
|
|
|
|
2019-12-18 23:54:23 +01:00
|
|
|
/**
|
|
|
|
* Ensures the chrome doesn't rerender every page load, which makes the sidebar reset its scroll.
|
|
|
|
*/
|
2019-11-08 03:40:20 +01:00
|
|
|
exports.wrapPageElement = ({ element, props }) => {
|
2019-12-18 23:54:23 +01:00
|
|
|
return (
|
|
|
|
<NodeProvider {...props}>
|
|
|
|
<Layout {...props}>
|
|
|
|
{element}
|
|
|
|
</Layout>
|
|
|
|
</NodeProvider>
|
|
|
|
);
|
2019-11-19 05:03:40 +01:00
|
|
|
};
|
|
|
|
|
2019-12-18 23:54:23 +01:00
|
|
|
|
2019-11-19 05:03:40 +01:00
|
|
|
exports.onRouteUpdate = ({location}) => {
|
2019-12-18 23:54:23 +01:00
|
|
|
if (window.ga && process.env.NODE_ENV === 'production') {
|
|
|
|
window.ga('send', 'pageview');
|
|
|
|
}
|
2019-11-19 05:03:40 +01:00
|
|
|
anchorScroll(location);
|
|
|
|
return true;
|
|
|
|
};
|
2019-12-18 23:54:23 +01:00
|
|
|
|
2019-11-19 05:03:40 +01:00
|
|
|
exports.shouldUpdateScroll = ({
|
|
|
|
routerProps: { location },
|
|
|
|
}) => {
|
|
|
|
anchorScroll(location);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const anchorScroll = location => {
|
|
|
|
// Check for location so build does not fail
|
|
|
|
if (location && location.hash) {
|
|
|
|
setTimeout(() => {
|
|
|
|
const item = document.querySelector(`${location.hash}`).offsetTop;
|
|
|
|
const mainNavHeight = document.querySelector(`header`).offsetHeight;
|
|
|
|
window.scrollTo({top: item - mainNavHeight, left: 0, behavior: 'smooth'});
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|