-
Notifications
You must be signed in to change notification settings - Fork 0
/
prismicio.js
41 lines (33 loc) · 1.04 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
import * as prismic from "@prismicio/client";
import * as prismicH from "@prismicio/helpers";
import * as prismicNext from "@prismicio/next";
import sm from "./sm.json";
/**
* The project's Prismic repository name.
*/
export const repositoryName = prismic.getRepositoryName(sm.apiEndpoint);
/**
* The project's Prismic Link Resolver. This function determines the URL for a given Prismic document.
*
* @type {prismicH.LinkResolverFunction}
*/
export const linkResolver = (doc) => {
if (doc.type === "article") {
return `/articles/${doc.uid}`;
}
if (doc.type === "page") {
return `/${doc.uid}`;
}
return "/";
};
/**
* Creates a Prismic client for the project's repository. The client is used to
* query content from the Prismic API.
*
* @param config {prismicNext.CreateClientConfig} - A configuration object to
*/
export const createClient = ({ previewData, req, ...config } = {}) => {
const client = prismic.createClient(sm.apiEndpoint, config);
prismicNext.enableAutoPreviews({ client, previewData, req });
return client;
};