-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismic-configuration.js
45 lines (37 loc) · 1.2 KB
/
prismic-configuration.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
45
import Prismic from "@prismicio/client";
import Link from "next/link";
import smConfig from "./sm.json";
if (!smConfig.apiEndpoint) {
console.warn("Looks like Slice Machine hasn't been bootstraped already.\nCheck the `Getting Started` section of the README file :)");
}
export const apiEndpoint = smConfig.apiEndpoint;
// -- Access Token if the repository is not public
// Generate a token in your dashboard and configure it here if your repository is private
export const accessToken = "";
// -- Link resolution rules
// Manages the url links to internal Prismic documents
export const linkResolver = (doc) => {
if (doc.type === "page") {
return `/${doc.uid}`;
}
return "/";
};
export const customLink = (type, element, content, children, index) => (
<Link
key={index}
href={linkResolver(element.data)}
as={linkResolver(element.data)}
>
<a>{content}</a>
</Link>
);
export const Router = {
routes: [{"type":"page","path":"/:uid"}],
href: (type) => {
const route = Router.routes.find(r => r.type === type);
return route && route.href;
}
};
export const Client = (req = null, options = {}) => (
Prismic.client(apiEndpoint, Object.assign({ routes: Router.routes }, options))
);