generated from ample/next-starter-ample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismicio.js
41 lines (32 loc) · 1006 Bytes
/
prismicio.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
// ---------------------------------------------------------
import * as prismic from '@prismicio/client'
import sm from './sm.json'
import { enableAutoPreviews } from '@prismicio/next'
// ---------------------------------------------------------
export const endpoint = sm.apiEndpoint
export const repositoryName = prismic.getRepositoryName(endpoint)
// ---------------------------------------------------------
// Update to match route structure
export const linkResolver = (document_) => {
switch (document_.type) {
case 'homepage':
return '/'
case 'flexible-page':
return `/${document_.uid}`
default:
return
}
}
// ---------------------------------------------------------
// This factory function allows smooth preview setup
export const createClient = (config = {}) => {
const client = prismic.createClient(endpoint, {
...config,
})
enableAutoPreviews({
client,
previewData: config.previewData,
req: config.req,
})
return client
}