-
Notifications
You must be signed in to change notification settings - Fork 0
/
prismicKits.js
53 lines (44 loc) · 1.38 KB
/
prismicKits.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
46
47
48
49
50
51
52
53
import Prismic from "prismic-javascript";
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 === "post") {
return `/blog/${doc.uid}`;
}
return "/";
};
// Additional helper function for Next/Link components
export const hrefResolver = (doc) => {
if (doc.type === "post") {
return "/blog/[uid]";
}
return "/";
};
export const customLink = (type, element, content, children, index) => (
<Link
key={index}
href={hrefResolver(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))
);