1
1
---
2
2
import { apiModules , getDoc } from " ./utils" ;
3
3
import StarlightPage from " @astrojs/starlight/components/StarlightPage.astro" ;
4
+ import { Code } from " @astrojs/starlight/components" ;
5
+ import { micromark } from " micromark" ;
4
6
5
7
export async function getStaticPaths() {
6
8
return apiModules .map ((apiModule ) => {
@@ -15,24 +17,60 @@ export async function getStaticPaths() {
15
17
16
18
const { moduleName, filePath } = Astro .props ;
17
19
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
+
18
41
const frontmatter = {
19
42
title: moduleName ,
20
43
};
21
44
22
45
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 ,
28
52
];
29
-
30
- const docInfo = await getDoc (filePath );
31
53
---
32
54
33
55
<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 >
38
71
</StarlightPage >
72
+ <style >
73
+ #apidocs .rescript_type {
74
+ margin-block: 2rem;
75
+ }
76
+ </style >
0 commit comments