forked from umd-mith/airwaves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
56 lines (47 loc) · 1.17 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
const { Index } = require('./src/search')
exports.onClientEntry = function(args, options) {
// get the index
const indexUrl = `${__PATH_PREFIX__}/data/index.json`
console.log(`loading ${indexUrl}`)
fetch(indexUrl)
.then(function(response) {
return response.json()
})
.then(function(data) {
const index = new Index()
index.import(data)
window.__INDEX__ = index
console.log(`created index`)
})
.catch(function(e) {
console.error(`Failed fetch search index: ${e}`)
})
// get the episodes
fetch(`${__PATH_PREFIX__}/data/episodes.json`)
.then((response) => {
return response.json()
})
.then((data) => {
window.__EPISODES__ = makeMap(data)
})
// get the documents
fetch(`${__PATH_PREFIX__}/data/documents.json`)
.then((response) => {
return response.json()
})
.then((data) => {
window.__DOCUMENTS__ = makeMap(data)
})
}
/**
* Creates a Map of the objects in a list using a given prop as a key
* @param {*} objectList
* @param {*} key
*/
function makeMap(objectList) {
const m = new Map()
for (const o of objectList) {
m.set(o['id'], o)
}
return m
}