Skip to content

Commit 32e7129

Browse files
committed
Add initial type modules
1 parent 26d4088 commit 32e7129

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

astro.config.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ const rescriptTM = JSON.parse(
77
readFileSync("./docs/assets/rescript.tmLanguage.json", "utf-8"),
88
);
99

10-
const apiSidebarItems = apiModules.map(({ moduleName, link }) => ({
11-
label: moduleName,
12-
link,
13-
}));
10+
const apiSidebarItems = apiModules.map(({ moduleName, link, items }) => {
11+
const nestedItems = Object.values(items).map(({ moduleName, link }) => ({
12+
label: moduleName,
13+
link
14+
}));
15+
16+
return ({
17+
label: moduleName,
18+
collapsed: true,
19+
items: [
20+
{
21+
label: `Overview`,
22+
link
23+
},
24+
...nestedItems
25+
]
26+
});
27+
});
1428

1529
export default defineConfig({
1630
srcDir: "docs",

docs/pages/apidocs/[API].astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function getStaticPaths() {
99
return apiModules.map((apiModule) => {
1010
return {
1111
params: {
12-
API: apiModule.apiRoute,
12+
API: apiModule.apiRouteParameter,
1313
},
1414
props: apiModule,
1515
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
import { apiModules, getDoc } from "../utils";
3+
// import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
4+
// import { Code } from "@astrojs/starlight/components";
5+
// import { micromark } from "micromark";
6+
// import Record from "../../components/record.astro";
7+
8+
export async function getStaticPaths() {
9+
return apiModules.flatMap((apiModule) => {
10+
return Object.values(apiModule.items).map((typeModule) => {
11+
return {
12+
params: {
13+
API: apiModule.apiRouteParameter,
14+
Module: typeModule.apiRouteParameter,
15+
},
16+
props: { parentModule: apiModule, currentModule: typeModule },
17+
};
18+
});
19+
});
20+
}
21+
22+
const name = Astro.props.currentModule.moduleName;
23+
---
24+
25+
<h1>Yupla {name}</h1>

docs/pages/apidocs/utils.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "node:path";
22
import { exec } from "node:child_process";
33
import { promisify } from "node:util";
4+
import { readdirSync, existsSync } from "fs";
45

56
const execAsync = promisify(exec);
67

@@ -15,17 +16,54 @@ export function createModuleLink(moduleName) {
1516
return `/apidocs/${toKebabCase(moduleName)}`;
1617
}
1718

19+
function mapTypeModules(parentModuleLink, file) {
20+
const folder = file.replace(".res", "");
21+
22+
if (!existsSync(folder)) {
23+
return [];
24+
}
25+
26+
const files = readdirSync(folder);
27+
return files
28+
.filter((f) => f.endsWith(".res"))
29+
.map((file) => {
30+
const fullPath = path.join(folder, file);
31+
32+
const moduleName = file
33+
.replace("$", "")
34+
.replace(folder, "")
35+
.replace(".res", "");
36+
const apiRouteParameter = toKebabCase(moduleName);
37+
const link = `${parentModuleLink}/${apiRouteParameter}`;
38+
const typeName = moduleName[0].toLocaleLowerCase() + moduleName.slice(1);
39+
40+
return [
41+
typeName,
42+
{
43+
fullPath,
44+
moduleName,
45+
link,
46+
apiRouteParameter,
47+
},
48+
];
49+
});
50+
}
51+
1852
function mapRescriptFile(file) {
1953
const moduleName = path
2054
.basename(file, ".res")
2155
.replace("$", "")
2256
.replace("API", " API");
57+
const filePath = path.join(import.meta.dirname, file);
2358
const link = createModuleLink(moduleName);
59+
const items = Object.fromEntries(mapTypeModules(link, filePath));
60+
2461
return {
25-
filePath: path.join(import.meta.dirname, file),
62+
filePath,
2663
moduleName,
2764
link,
28-
apiRoute: toKebabCase(moduleName),
65+
apiRouteParameter: toKebabCase(moduleName),
66+
items,
2967
};
3068
}
3169

docs/styles/theme.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
:root,
22
::backdrop {
33
--sl-font: "Inter", "Roboto Mono";
4+
--sl-sidebar-width: 23rem;
45
}
56

67
/*

0 commit comments

Comments
 (0)