-
Notifications
You must be signed in to change notification settings - Fork 793
Expand file tree
/
Copy pathresolve-component.tsx
More file actions
126 lines (112 loc) · 3.16 KB
/
resolve-component.tsx
File metadata and controls
126 lines (112 loc) · 3.16 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { PageDataWithoutComponent } from "./page-utils";
export const serveLocal = (search?: { local?: "true" | "false" }) => {
let useLocal = false;
if (process.env.SERVE_LOCAL === "false") {
return false;
}
if (process.env.SERVE_LOCAL === "true") {
return true;
}
if (process.env.NODE_ENV === "development") {
useLocal = true;
if (search?.local === "false") {
useLocal = false;
}
}
return useLocal;
};
export const serveLocalAsync = async (
searchParams?: Promise<{
local?: "true" | "false";
}>
) => {
const search = await searchParams;
// @todo, don't hard code this to true
// https://github.com/pantheon-systems/documentation-in-nextjs/issues/84
return true;
// return serveLocal(search);
};
export const resolveComponent = async (
pageData: PageDataWithoutComponent & { relativeFilePath?: string }
): Promise<{ Component: React.ReactNode; template: string }> => {
switch (pageData.type) {
case "doc": {
const Doc = await import(`@/templates/doc`);
return {
Component: <Doc.DocTemplate doc={pageData.data.doc} />,
template: "doc",
};
}
case "guide": {
const Doc = await import(`@/templates/doc`);
return {
Component: (
<Doc.DocTemplate
doc={pageData.data.guide}
prev={pageData.data.prev}
next={pageData.data.next}
tocDefault={false}
/>
),
template: "guide",
};
}
case "terminus-command": {
const TerminusCommand = await import(`@/templates/terminus-command`);
return {
Component: (
<TerminusCommand.TerminusCommandTemplate
command={pageData.data}
slug={pageData.data.slug}
/>
),
template: "terminus-command",
};
}
case "release-note": {
const ReleaseNote = await import(`@/templates/release-note`);
return {
Component: (
<ReleaseNote.ReleaseNoteTemplate releaseNote={pageData.data} />
),
template: "release-note",
};
}
case "release-note-listing": {
const ReleaseNoteListing = await import(
`@/templates/release-note-listing`
);
return {
Component: (
<ReleaseNoteListing.ReleaseNoteListingTemplate
pageNumber={pageData.data.pageNumber}
releaseNotes={pageData.data.releaseNotes}
categories={pageData.data.categories}
totalPages={pageData.data.totalPages}
/>
),
template: "release-note-listing",
};
}
case "iframe-embed": {
const IframeEmbed = await import(`@/templates/iframe-embed`);
return {
Component: (
<IframeEmbed.IframeEmbedTemplate
iframeEmbed={pageData.data.iframeEmbed}
/>
),
template: "iframe-embed",
};
}
case "landing": {
const Landing = await import(`@/templates/landing`);
return {
Component: <Landing.LandingTemplate topic={pageData.data.landing} />,
template: "landing",
};
}
default:
throw new Error(`Unknown page type: ${(pageData as any).type}`);
}
};