-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismic-configuration.js
55 lines (47 loc) · 1.34 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
46
47
48
49
50
51
52
53
54
55
import {Client} from "@prismicio/client";
import Link from "next/link";
import smConfig from "./slicemachine.config.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}`;
}
if (doc.type === "redirect") {
return `/${doc.uid}`;
}
return "/";
};
export const customLink = (type, element, content, children, index) => (
<Link
key={index}
href={linkResolver(element.data)}
as={linkResolver(element.data)}
>
{content}
</Link>
);
export const Router = {
routes: [
{ type: "page", path: "/:uid" },
{ type: "redirect", path: "/:uid" },
],
href: (type) => {
const route = Router.routes.find((r) => r.type === type);
return route && route.href;
},
};
export const MyClient = (req = null, options = {}) =>
new Client(
apiEndpoint,
Object.assign({ routes: Router.routes }, options)
);