-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismicio.js
58 lines (52 loc) · 1.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
export const linkResolver = (doc) => {
const lang = doc.lang === "fr" ? "" : `/${doc.lang}`;
let url = `${lang}/${doc.uid}`;
if (doc.uid === "home") {
url = "/";
return url;
}
if (doc.type === "page") {
url = `${lang}/${doc.uid}`;
return url;
}
if (doc.type === "post") {
url = `${lang}/blog/${doc.uid}`;
return url;
}
return url;
};
export const webLinkResolver = (url) => {
if (url.includes("https://action:")) return "";
if (url.includes("https://#")) return url.replace("https://", "");
return url;
};
/**
* 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 = (config = {}) => {
const client = prismic.createClient(sm.apiEndpoint, {
routes: [
{
type: "page",
uid: "home",
path: "/",
},
{ type: "page", path: "/:uid" },
{ type: "post", path: "/blog/:uid" },
{ type: "settings", path: "/" },
{ type: "navigation", path: "/" },
],
});
return client;
};