Skip to content

Commit 5ab495c

Browse files
committed
add belt and dom apis to docs
1 parent 1453313 commit 5ab495c

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

app/routes.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,24 @@ tmp = typeof json === "object" && json !== null && !Array.isArray(json) ? Object
1515

1616
let stdlibPaths = tmp.map(key => "docs/manual/api/" + key).filter(path => path !== "docs/manual/api/stdlib");
1717

18+
let rawFile$1 = await Promises.readFile("./docs/api/belt.json", "utf-8");
19+
20+
let json$1 = JSON.parse(rawFile$1);
21+
22+
let tmp$1;
23+
24+
tmp$1 = typeof json$1 === "object" && json$1 !== null && !Array.isArray(json$1) ? Object.keys(json$1) : [];
25+
26+
let beltPaths = tmp$1.map(key => "docs/manual/api/" + key).filter(path => path !== "docs/manual/api/belt");
27+
1828
let stdlibRoutes = stdlibPaths.map(path => Routes.route(path, "./routes/ApiRoute.mjs", {
1929
id: path
2030
}));
2131

32+
let beltRoutes = beltPaths.map(path => Routes.route(path, "./routes/ApiRoute.mjs", {
33+
id: path
34+
}));
35+
2236
let $$default = Belt_Array.concatMany([
2337
[
2438
Routes.index("./routes/LandingPageRoute.mjs"),
@@ -47,13 +61,16 @@ let $$default = Belt_Array.concatMany([
4761
})
4862
],
4963
stdlibRoutes,
64+
beltRoutes,
5065
Server.routes("./routes/MdxRoute.mjs"),
5166
[Routes.route("*", "./routes/NotFoundRoute.mjs")]
5267
]);
5368

5469
export {
5570
stdlibPaths,
71+
beltPaths,
5672
stdlibRoutes,
73+
beltRoutes,
5774
$$default as default,
5875
}
5976
/* rawFile Not a pure module */

app/routes.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@ let stdlibPaths = {
1111
->Array.filter(path => path !== "docs/manual/api/stdlib")
1212
}
1313

14+
let beltPaths = {
15+
let rawFile = await Node.Fs.readFile("./docs/api/belt.json", "utf-8")
16+
let json = JSON.parseOrThrow(rawFile)
17+
switch json {
18+
| Object(json) => Dict.keysToArray(json)
19+
| _ => []
20+
}
21+
->Array.map(key => "docs/manual/api/" ++ key)
22+
->Array.filter(path => path !== "docs/manual/api/belt")
23+
}
24+
1425
let stdlibRoutes =
1526
stdlibPaths->Array.map(path => route(path, "./routes/ApiRoute.mjs", ~options={id: path}))
1627

28+
let beltRoutes =
29+
beltPaths->Array.map(path => route(path, "./routes/ApiRoute.mjs", ~options={id: path}))
30+
1731
let default = [
1832
index("./routes/LandingPageRoute.mjs"),
1933
route("packages", "./routes/PackagesRoute.mjs"),
@@ -26,6 +40,7 @@ let default = [
2640
route("docs/manual/api/belt", "./routes/ApiRoute.mjs", ~options={id: "api-belt"}),
2741
route("docs/manual/api/dom", "./routes/ApiRoute.mjs", ~options={id: "api-dom"}),
2842
...stdlibRoutes,
43+
...beltRoutes,
2944
...mdxRoutes("./routes/MdxRoute.mjs"),
3045
route("*", "./routes/NotFoundRoute.mjs"),
3146
]

app/routes/ApiRoute.res

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ let rec rawApiItemToNode = (apiItem: apiItem): ApiDocs.node => {
1313
name: apiItem.name,
1414
path: apiItem.id
1515
->String.split(".")
16-
->Array.filter(segment => segment !== "Stdlib" && segment !== "Belt" && segment !== "Js"),
16+
->Array.filter(segment =>
17+
segment !== "Stdlib" && segment !== "Belt" && segment !== "Js" && segment !== "Dom"
18+
),
1719
children: apiItem.items
1820
->Option.map(items =>
1921
Array.filter(items, item =>
@@ -101,9 +103,15 @@ let loader: ReactRouter.Loader.t<loaderData> = async args => {
101103
->String.replace("/docs/manual/api/", "")
102104
->String.split("/")
103105

104-
let apiDocs = parseApi(await Node.Fs.readFile("./docs/api/stdlib.json", "utf-8"))
106+
let basePath = path[0]->Option.getUnsafe
105107

106-
let stdlibToc = apiDocs->Dict.get("stdlib")
108+
let apiDocs = switch basePath {
109+
| "belt" => parseApi(await Node.Fs.readFile("./docs/api/belt.json", "utf-8"))
110+
| "dom" => parseApi(await Node.Fs.readFile("./docs/api/dom.json", "utf-8"))
111+
| _ => parseApi(await Node.Fs.readFile("./docs/api/stdlib.json", "utf-8"))
112+
}
113+
114+
let stdlibToc = apiDocs->Dict.get(basePath)
107115

108116
let toctree = groupItems(apiDocs)
109117

@@ -121,7 +129,7 @@ let loader: ReactRouter.Loader.t<loaderData> = async args => {
121129
{
122130
module_: item.module_,
123131
toctree: {
124-
name: "Stdlib",
132+
name: basePath->String.capitalize,
125133
path: [],
126134
children: toctree,
127135
},

src/ApiDocs.res

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ module SidebarTree = {
230230
<div className="hl-overline text-gray-80 mt-5 mb-2"> {"submodules"->React.string} </div>
231231
{node.children
232232
->Array.toSorted((v1, v2) => String.compare(v1.name, v2.name))
233+
->Array.filter(child => child.name !== node.name)
233234
->Array.map(renderNode)
234235
->React.array}
235236
</aside>
@@ -403,7 +404,7 @@ module Data = {
403404

404405
let pathModule = Path.join([dir, `${moduleName}.json`])
405406

406-
let moduleContent = Fs.readFileSync("docs/api/stdlib.json")->JSON.parseOrThrow
407+
let moduleContent = Fs.readFileSync(`docs/api/${moduleName}.json`)->JSON.parseOrThrow
407408

408409
let content = switch moduleContent {
409410
| Object(dict) => dict->Some
@@ -424,9 +425,16 @@ let processStaticProps = (~slug: array<string>) => {
424425
let content =
425426
// TODO post RR7: rename this to getByModuleName
426427
Data.getVersion(~moduleName)
427-
->Option.map(data => data.mainModule)
428+
->Option.map(data => {
429+
let x = data.mainModule
430+
Console.log(modulePath)
431+
Console.log(x->Dict.keysToArray)
432+
x
433+
})
428434
->Option.flatMap(Dict.get(_, modulePath))
429435

436+
// Console.log(content)
437+
430438
let _content = content
431439

432440
switch content {

0 commit comments

Comments
 (0)