Skip to content

Commit 6430d27

Browse files
committed
Render types with documentation and signature
1 parent 3c74fe8 commit 6430d27

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

docs/pages/apidocs/[API].astro

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
import { apiModules, getDoc } from "./utils";
33
import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro";
4+
import { Code } from "@astrojs/starlight/components";
5+
import { micromark } from "micromark";
46
57
export async function getStaticPaths() {
68
return apiModules.map((apiModule) => {
@@ -15,24 +17,60 @@ export async function getStaticPaths() {
1517
1618
const { moduleName, filePath } = Astro.props;
1719
20+
const docInfo = await getDoc(filePath);
21+
22+
const types = docInfo.items
23+
.filter((item) => item.kind === "type")
24+
.sort((a, b) => a.name.localeCompare(b.name))
25+
.map((type) => {
26+
const documentation =
27+
type.docstrings && micromark(type.docstrings.join("\n"));
28+
return {
29+
name: type.name,
30+
documentation,
31+
signature: type.signature,
32+
};
33+
});
34+
35+
const typeHeadings = types.map((type) => ({
36+
depth: 3,
37+
slug: type.name,
38+
text: type.name,
39+
}));
40+
1841
const frontmatter = {
1942
title: moduleName,
2043
};
2144
2245
const headings = [
23-
// {
24-
// depth: 2,
25-
// slug: "web-apis",
26-
// text: "Web APIs",
27-
// },
46+
{
47+
depth: 2,
48+
slug: "types",
49+
text: "Types",
50+
},
51+
...typeHeadings,
2852
];
29-
30-
const docInfo = await getDoc(filePath);
3153
---
3254

3355
<StarlightPage frontmatter={frontmatter} headings={headings}>
34-
<h2>{moduleName} overview</h2>
35-
<code>
36-
<pre>{JSON.stringify(docInfo, null, 4)}</pre>
37-
</code>
56+
<div id="apidocs">
57+
<h2 id="types">Types</h2>
58+
{
59+
types.map((type) => (
60+
<div class="rescript_type">
61+
<h3 id={type.name}>{type.name}</h3>
62+
<div set:html={type.documentation} />
63+
<Code lang="ReScript" code={type.signature} />
64+
</div>
65+
))
66+
}
67+
<code>
68+
<pre>{JSON.stringify(docInfo, null, 4)}</pre>
69+
</code>
70+
</div>
3871
</StarlightPage>
72+
<style>
73+
#apidocs .rescript_type {
74+
margin-block: 2rem;
75+
}
76+
</style>

docs/styles/theme.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ https://github.com/rescript-lang/rescript-lang.org/blob/4e4f9520f6fc7a0376db82a0
2121
}
2222
}
2323

24-
body {
24+
body, #starlight__sidebar {
2525
--scrollbar-track-background: #222222;
2626
--scrollbar-track-border: #4a4a4a;
2727
--scrollbar-thumb-background: #686868;

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"devDependencies": {
4141
"@astrojs/starlight": "^0.29.0",
4242
"astro": "^4.16.10",
43+
"micromark": "^4.0.1",
4344
"prettier": "^3.3.3",
4445
"prettier-plugin-astro": "^0.14.1",
4546
"sharp": "^0.33.5"

0 commit comments

Comments
 (0)