-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
59 lines (52 loc) · 1.47 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
51
52
53
54
55
56
57
58
59
import "normalize.css";
import "theme/global.css";
import Layout from "components/layout";
import SiteProvider from "providers/siteContext";
import ThemeProvider from "providers/themeContext";
import { MDXProvider } from "@mdx-js/react";
import mdxComponents from "components/mdxComponents";
export const wrapRootElement = ({ element }) => (
<ThemeProvider>
<MDXProvider components={mdxComponents}>
<SiteProvider>{element}</SiteProvider>
</MDXProvider>
</ThemeProvider>
);
export const wrapPageElement = ({ element, props }) => {
return <Layout {...props}>{element}</Layout>;
};
export const onServiceWorkerUpdateReady = () => {
window.location.reload();
};
export const shouldUpdateScroll = ({ routerProps: { location } }) => {
if (location && location.hash) {
const anchorLink = document.querySelector(location.hash);
anchorLink &&
window.scrollTo({
top: anchorLink.offsetTop,
});
return false;
}
return true;
};
export const onClientEntry = (
_,
{ filename = "searchIndex.json", fetchOptions = {} }
) => {
globalThis.__FUSE__ = globalThis.__FUSE__ || {};
globalThis.__FUSE__.__loaded = fetch(
`${__PATH_PREFIX__}/${filename}`,
fetchOptions
)
.then(function (response) {
return response.json();
})
.then(function (fullIndex) {
globalThis.__FUSE__ = fullIndex;
return globalThis.__FUSE__;
})
.catch((e) => {
console.log("Failed fetch search index");
throw e;
});
};