@@ -11,7 +11,6 @@ module Category = Sidebar.Category;
11
11
12
12
let makeBreadcrumbsFromPaths =
13
13
(~basePath: string , paths: array (string )): list(Url . breadcrumb) => {
14
- Js . log(paths);
15
14
let (_ , rest ) =
16
15
Belt . Array . reduce(
17
16
paths,
@@ -21,8 +20,7 @@ let makeBreadcrumbsFromPaths =
21
20
22
21
let href = baseHref ++ "/" ++ path;
23
22
24
- Js . Array2 . push(ret, Url . {name: prettyString(path), href})
25
- -> ignore ;
23
+ Js . Array2 . push(ret, Url . {name: prettyString(path), href})-> ignore ;
26
24
(href, ret);
27
25
},
28
26
);
@@ -42,8 +40,7 @@ let makeBreadcrumbs =
42
40
43
41
let href = baseHref ++ "/" ++ path;
44
42
45
- Js . Array2 . push(ret, Url . {name: prettyString(path), href})
46
- -> ignore ;
43
+ Js . Array2 . push(ret, Url . {name: prettyString(path), href})-> ignore ;
47
44
(href, ret);
48
45
},
49
46
);
@@ -55,6 +52,7 @@ let make =
55
52
(
56
53
~breadcrumbs: option (list (Url . breadcrumb ))=?,
57
54
~title: string ,
55
+ ~metaTitleCategory: option (string )=?, // e.g. Introduction | My Meta Title Category
58
56
~frontmatter: option (Js . Json . t )=?,
59
57
~version: option (string )=?,
60
58
~availableVersions: option (array (string ))=?,
@@ -139,7 +137,12 @@ let make =
139
137
route
140
138
/>;
141
139
142
- let metaTitle = title ++ " | ReScript Documentation" ;
140
+ let metaTitle =
141
+ switch (metaTitleCategory) {
142
+ | Some (titleCategory ) =>
143
+ titleCategory ++ " | " ++ "ReScript Documentation"
144
+ | None => title
145
+ };
143
146
144
147
let metaElement =
145
148
switch (frontmatter) {
@@ -148,7 +151,11 @@ let make =
148
151
| Ok (fm ) =>
149
152
let canonical = Js . Null . toOption(fm. canonical);
150
153
let description = Js . Null . toOption(fm. description);
151
- let title = fm. title ++ " | ReScript Language Manual" ;
154
+ let title =
155
+ switch (metaTitleCategory) {
156
+ | Some (titleCategory ) => fm. title ++ " | " ++ titleCategory
157
+ | None => title
158
+ };
152
159
<Meta title ?description ?canonical />;
153
160
| Error (_ ) => React . null
154
161
}
@@ -166,3 +173,92 @@ let make =
166
173
children
167
174
</SidebarLayout >;
168
175
};
176
+
177
+ module type StaticContent = {
178
+ /* let categories: array(SidebarLayout.Sidebar.Category.t);*/
179
+ let tocData : SidebarLayout . Toc . raw ;
180
+ };
181
+
182
+ module Make = (Content : StaticContent ) => {
183
+ [@ react . component ]
184
+ let make =
185
+ (
186
+ ~breadcrumbs: option (list (Url . breadcrumb ))=?,
187
+ ~title: string ,
188
+ ~metaTitleCategory: option (string )=?,
189
+ ~frontmatter: option (Js . Json . t )=?,
190
+ ~version: option (string )=?,
191
+ ~availableVersions: option (array (string ))=?,
192
+ ~latestVersionLabel: option (string )=?,
193
+ /* ~activeToc: option(SidebarLayout.Toc.t)=?,*/
194
+ ~components: option (Mdx . Components . t )=?,
195
+ ~theme: option (ColorTheme . t )=?,
196
+ ~children: React . element ,
197
+ ) => {
198
+ let router = Next . Router . useRouter() ;
199
+ let route = router. route;
200
+
201
+ let activeToc : option (SidebarLayout . Toc . t ) =
202
+ Belt . Option . (
203
+ Js . Dict . get(Content . tocData, route)
204
+ -> map(data => {
205
+ open SidebarLayout . Toc ;
206
+ let title = data## title;
207
+ let entries =
208
+ Belt . Array . map(data## headers, header =>
209
+ {header: header## name, href: "#" ++ header## href}
210
+ );
211
+ {title, entries};
212
+ })
213
+ );
214
+
215
+ let categories = {
216
+ let groups =
217
+ Js . Dict . entries(Content . tocData)
218
+ -> Belt . Array . reduce(
219
+ Js . Dict . empty() ,
220
+ (acc, next) => {
221
+ let (_ , value ) = next;
222
+ switch (Js . Nullable . toOption(value## category)) {
223
+ | Some (category ) =>
224
+ switch (acc-> Js . Dict . get(category)) {
225
+ | None => acc-> Js . Dict . set(category, [| next|] )
226
+ | Some (arr ) =>
227
+ Js . Array2 . push(arr, next)-> ignore ;
228
+ acc-> Js . Dict . set(category, arr);
229
+ }
230
+ | None =>
231
+ Js . log2("has NO category" , next);
232
+ ()
233
+ };
234
+ acc;
235
+ },
236
+ );
237
+ Js . Dict . entries(groups)
238
+ -> Belt . Array . map(((name, values)) => {
239
+ Category . {
240
+ name,
241
+ items:
242
+ Belt . Array . map(values, ((href, value)) => {
243
+ {NavItem . name: value## title, href}
244
+ }),
245
+ }
246
+ });
247
+ };
248
+
249
+ make({
250
+ "breadcrumbs" : breadcrumbs,
251
+ "title" : title,
252
+ "metaTitleCategory" : metaTitleCategory,
253
+ "frontmatter" : frontmatter,
254
+ "version" : version,
255
+ "availableVersions" : availableVersions,
256
+ "latestVersionLabel" : latestVersionLabel,
257
+ "activeToc" : activeToc,
258
+ "categories" : categories,
259
+ "components" : components,
260
+ "theme" : theme,
261
+ "children" : children,
262
+ });
263
+ };
264
+ };
0 commit comments