-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
42 lines (36 loc) · 944 Bytes
/
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
require('prism-theme-night-owl')
require('prismjs/plugins/line-numbers/prism-line-numbers.css')
/**
* Alert visitors that new data is avail since data comes from a service worker
*/
exports.onServiceWorkerUpdateReady = () => {
const answer = window.confirm(
`Hey! There's some new data since you last visited.` +
`Reload the page to display the latest version?`
)
if (answer === true) {
caches
.keys()
.then(names => {
for (let name of names) {
caches.delete(name)
}
})
.then(() => {
window.location.reload()
})
}
}
/**
* Set focus on skip to content if navigating from a previous page. Allows for easier toggling if navigating around
*/
exports.onRouteUpdate = ({ prevLocation }) => {
if (prevLocation === null) {
return
}
const skipLink = document.querySelector('#reach-skip-nav')
if (!skipLink) {
return
}
skipLink.focus()
}