Skip to content

Commit 778f521

Browse files
committed
api prerender is working
1 parent 5a5904f commit 778f521

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24

app/routes.mjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
4+
import * as Promises from "node:fs/promises";
45
import * as Server from "react-router-mdx/server";
56
import * as Routes from "@react-router/dev/routes";
67

8+
let rawFile = await Promises.readFile("./docs/api/stdlib.json", "utf-8");
9+
10+
let json = JSON.parse(rawFile);
11+
12+
let tmp;
13+
14+
tmp = typeof json === "object" && json !== null && !Array.isArray(json) ? Object.keys(json) : [];
15+
16+
let stdlibPaths = tmp.map(key => "docs/manual/api/" + key).filter(path => path !== "docs/manual/api/stdlib");
17+
18+
let stdlibRoutes = stdlibPaths.map(path => Routes.route(path, "./routes/ApiRoute.mjs", {
19+
id: path
20+
}));
21+
722
let $$default = Belt_Array.concatMany([
823
[
924
Routes.index("./routes/LandingPageRoute.mjs"),
@@ -18,9 +33,6 @@ let $$default = Belt_Array.concatMany([
1833
Routes.route("docs/manual/api/stdlib", "./routes/ApiRoute.mjs", {
1934
id: "api-stdlib"
2035
}),
21-
Routes.route("docs/manual/api/stdlib/bigint", "./routes/ApiRoute.mjs", {
22-
id: "api-stdlib-bigint"
23-
}),
2436
Routes.route("docs/manual/api/introduction", "./routes/ApiRoute.mjs", {
2537
id: "api-intro"
2638
}),
@@ -31,10 +43,13 @@ let $$default = Belt_Array.concatMany([
3143
id: "api-dom"
3244
})
3345
],
46+
stdlibRoutes,
3447
Server.routes("./routes/MdxRoute.mjs")
3548
]);
3649

3750
export {
51+
stdlibPaths,
52+
stdlibRoutes,
3853
$$default as default,
3954
}
40-
/* default Not a pure module */
55+
/* rawFile Not a pure module */

app/routes.res

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
open ReactRouter.Routes
22
open ReactRouter.Mdx
33

4+
let stdlibPaths = {
5+
let rawFile = await Node.Fs.readFile("./docs/api/stdlib.json", "utf-8")
6+
let json = JSON.parseOrThrow(rawFile)
7+
switch json {
8+
| Object(json) => Dict.keysToArray(json)
9+
| _ => []
10+
}
11+
->Array.map(key => "docs/manual/api/" ++ key)
12+
->Array.filter(path => path !== "docs/manual/api/stdlib")
13+
}
14+
15+
let stdlibRoutes =
16+
stdlibPaths->Array.map(path => route(path, "./routes/ApiRoute.mjs", ~options={id: path}))
17+
418
let default = [
519
index("./routes/LandingPageRoute.mjs"),
620
route("packages", "./routes/PackagesRoute.mjs"),
@@ -10,13 +24,9 @@ let default = [
1024
route("syntax-lookup", "./routes/SyntaxLookupRoute.mjs"),
1125
route("blog", "./routes/BlogRoute.mjs"),
1226
route("docs/manual/api/stdlib", "./routes/ApiRoute.mjs", ~options={id: "api-stdlib"}),
13-
route(
14-
"docs/manual/api/stdlib/bigint", // TODO RR7: generate routes for all api docs
15-
"./routes/ApiRoute.mjs",
16-
~options={id: "api-stdlib-bigint"},
17-
),
1827
route("docs/manual/api/introduction", "./routes/ApiRoute.mjs", ~options={id: "api-intro"}),
1928
route("docs/manual/api/belt", "./routes/ApiRoute.mjs", ~options={id: "api-belt"}),
2029
route("docs/manual/api/dom", "./routes/ApiRoute.mjs", ~options={id: "api-dom"}),
30+
...stdlibRoutes,
2131
...routes("./routes/MdxRoute.mjs"),
2232
]

react-router.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as fs from "node:fs";
22
import { init } from "react-router-mdx/server";
33

4+
45
const mdx = init({ paths: ["_blogposts", "docs"], aliases: ["blog", "docs"] });
56

7+
const { stdlibPaths } = await import("./app/routes.mjs");
8+
69
export default {
710
ssr: false,
811

912
async prerender({ getStaticPaths }) {
10-
return [...(await getStaticPaths()), ...(await mdx.paths())];
13+
return [...(await getStaticPaths()), ...(await mdx.paths()), ...stdlibPaths];
1114
},
1215
buildEnd: async () => {
1316
fs.cpSync("./build/client", "./out", { recursive: true });

0 commit comments

Comments
 (0)