-
Notifications
You must be signed in to change notification settings - Fork 1
/
prismicio.js
34 lines (29 loc) · 869 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
import * as prismic from '@prismicio/client'
import { enableAutoPreviews } from '@prismicio/next'
import sm from './sm.json'
export const endpoint = sm.apiEndpoint
export const repositoryName = prismic.getRepositoryName(endpoint)
// Update the Link Resolver to match your project's route structure
export function linkResolver(doc) {
switch (doc.type) {
case 'homepage':
return '/'
case 'page':
return `/${doc.uid}`
default:
return null
}
}
// This factory function allows smooth preview setup
export function createClient(config = {}) {
const client = prismic.createClient(endpoint, {
accessToken: process.env.ACCESS_TOKEN,
...config,
})
enableAutoPreviews({
client,
previewData: config.previewData,
req: config.req,
})
return client
}