-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprismicio.js
44 lines (39 loc) · 1.13 KB
/
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
42
43
44
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);
const ACCESS_TOKEN = process.env.PRISMIC_ACCESS_TOKEN;
// Update the Link Resolver to match your project's route structure
export function linkResolver(doc) {
if (doc.type === 'blogPost') {
return `/blog/${doc.uid}`;
}
if (doc.type === 'educationCenterContent') {
switch (doc.lang) {
case 'nl-nl':
case 'nl-be':
return `/kennisbank/${doc.uid}`;
case 'de-de':
return `/datenbank/${doc.uid}`;
case 'fr-fr':
return `/centre-de-connaissance/${doc.uid}`;
default:
return `/education-center/${doc.uid}`;
}
}
return '/';
}
// This factory function allows smooth preview setup
export function createClient(config = {}) {
const client = prismic.createClient(endpoint, {
...config,
accessToken: ACCESS_TOKEN,
});
enableAutoPreviews({
client,
previewData: config.previewData,
req: config.req,
});
return client;
}