-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
53 lines (50 loc) · 1.3 KB
/
index.ts
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 WPApi from "wpapi";
/* Wuxt extension */
/* Initialy created by Daniel Auener https://github.com/northosts/wuxt */
/* Wordpress extension: https://github.com/northosts/wuxt/tree/master/wp-content/mu-plugins/wuxt-headless-wp-api-extensions */
function checkWpApi(wp: WPApi) {
if (!wp && typeof wp.registerRoute !== "function") {
console.log("Please provide a wpapi instance.");
}
}
function registerCpt(wp: WPApi) {
checkWpApi(wp);
wp.cpt = postType => {
wp[postType] = wp.registerRoute("wp/v2", "/" + postType + "/(?P<id>)", {
params: ["embed", "before", "after", "author", "parent", "post"]
});
return wp[postType]();
};
}
function registerFrontPage(wp: WPApi) {
checkWpApi(wp);
wp.frontPage = wp.registerRoute("wuxt/v1", "/front-page", {
params: ["embed"]
});
}
function registerMenu(wp: WPApi) {
checkWpApi(wp);
wp.menu = wp.registerRoute("wuxt/v1", "/menu", {
params: ["location"]
});
}
function registerSlug(wp: WPApi) {
checkWpApi(wp);
wp.slug = wp.registerRoute("wuxt/v1", "/slug/(?P<name>)", {
params: ["embed"]
});
}
function registerWuxt(wp: WPApi) {
checkWpApi(wp);
registerFrontPage(wp);
registerMenu(wp);
registerSlug(wp);
registerCpt(wp);
}
export {
registerWuxt,
registerCpt,
registerFrontPage,
registerSlug,
registerMenu
};