1
1
---
2
- import * as path from " node:path" ;
3
- import { existsSync } from " fs" ;
4
- import { apiModules , getDoc , createTypeModuleLink } from " ../../utils" ;
5
- import StarlightPage from " @astrojs/starlight/components/StarlightPage.astro" ;
6
- import { Code } from " @astrojs/starlight/components" ;
7
- import { micromark } from " micromark" ;
8
- import Record from " ../../components/record.astro" ;
2
+ import { apiModules } from " ../../utils" ;
3
+ import APIDoc from " ../../components/apidoc.astro" ;
9
4
10
5
export async function getStaticPaths() {
11
6
return apiModules .map ((apiModule ) => {
@@ -18,97 +13,7 @@ export async function getStaticPaths() {
18
13
});
19
14
}
20
15
21
- function showRecord(details ) {
22
- return details && details .kind === " record" && details .items .length > 0 ;
23
- }
24
-
25
- function getModuleFileName(typeName ) {
26
- return ` ${typeName [0 ].toUpperCase ()}${typeName .slice (1 )} ` ;
27
- }
28
-
29
- function showModule(typeName , filePath ) {
30
- const moduleFileName = ` ${getModuleFileName (typeName )}.res ` ;
31
- const potentialPath = path .join (filePath .replace (" .res" , " " ), moduleFileName );
32
- return existsSync (potentialPath );
33
- }
34
-
35
16
const { moduleName, filePath, link } = Astro .props ;
36
-
37
- const docInfo = await getDoc (filePath );
38
-
39
- const types = docInfo .items
40
- .filter ((item ) => item .kind === " type" )
41
- .sort ((a , b ) => a .name .localeCompare (b .name ))
42
- .map ((type ) => {
43
- const documentation =
44
- type .docstrings && micromark (type .docstrings .join (" \n " ));
45
- return {
46
- name: type .name ,
47
- documentation ,
48
- signature: type .signature ,
49
- detail: type .detail ,
50
- };
51
- });
52
-
53
- const typesInOwnModule = new Set (types .map ((t ) => t .name ));
54
-
55
- const typeHeadings = types .map ((type ) => ({
56
- depth: 3 ,
57
- slug: type .name ,
58
- text: type .name ,
59
- }));
60
-
61
- const frontmatter = {
62
- title: moduleName ,
63
- };
64
-
65
- const headings = [
66
- {
67
- depth: 2 ,
68
- slug: " types" ,
69
- text: " Types" ,
70
- },
71
- ... typeHeadings ,
72
- ];
73
17
---
74
18
75
- <StarlightPage frontmatter ={ frontmatter } headings ={ headings } >
76
- <div id =" apidocs" >
77
- <h2 id =" types" >Types</h2 >
78
- {
79
- types .map ((type ) => (
80
- <div class = " rescript_type" >
81
- <h3 id = { type .name } >{ type .name } </h3 >
82
- <div set :html = { type .documentation } />
83
- <Code lang = " ReScript" code = { type .signature } />
84
- { showRecord (type .detail ) ? (
85
- <Record
86
- name = { type .name }
87
- typesInOwnModule = { typesInOwnModule }
88
- { ... type .detail }
89
- />
90
- ) : null }
91
- { showModule (type .name , filePath ) && (
92
- <>
93
- <h4 >Module</h4 >
94
- <p >
95
- There are methods and helpers defined in{ " " }
96
- <a
97
- href = { ` ${import .meta .env .BASE_URL }/${createTypeModuleLink (link , type .name )} ` }
98
- >
99
- { getModuleFileName (type .name )}
100
- </a >
101
- .
102
- </p >
103
- </>
104
- )}
105
- </div >
106
- ))
107
- }
108
- </div >
109
- </StarlightPage >
110
- <style >
111
- #apidocs .rescript_type {
112
- margin-block: 2rem;
113
- }
114
- </style >
19
+ <APIDoc moduleName ={ moduleName } filePath ={ filePath } link ={ link } />
0 commit comments