-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprismic-config.js
More file actions
executable file
·52 lines (42 loc) · 1.29 KB
/
Copy pathprismic-config.js
File metadata and controls
executable file
·52 lines (42 loc) · 1.29 KB
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
const prismicRepoName = 'sample-site';
module.exports = {
prismicRepoName: prismicRepoName,
apiEndpoint: `https://${prismicRepoName}.prismic.io/api/v2`,
// -- Link Resolver
// This function will be used to generate links to Prismic documents
linkResolver(doc) {
if (doc.type === 'page') return '/' + doc.uid;
return '/';
},
// -- Toolbar Refresh
// This function will be used to refresh the Prismic Toolbar
refreshToolbar() {
this.waitForGlobal('PrismicToolbar').then(() => {
if (window.PrismicToolbar) {
window.PrismicToolbar.setup(exports.apiEndpoint);
window.PrismicToolbar.setupEditButton();
}
});
},
// -- Wait for Global
// This function will be used to wait for javascript libraries to load in the window
waitForGlobal(name, timeout = 300) {
return new Promise((resolve, reject) => {
let waited = 0
function wait(interval) {
setTimeout(() => {
waited += interval
// Check if script is loaded
if (window[name] !== undefined) {
return resolve()
}
if (waited >= timeout * 1000) {
return reject({ message: 'Timeout' })
}
wait(interval * 2)
}, interval)
}
wait(30)
})
},
};