@@ -54,9 +54,10 @@ module SidebarTree = {
54
54
let summaryClassName = "truncate py-1 md:h-auto tracking-tight text-gray-60 font-medium text-14 rounded-sm hover:bg-gray-20 hover:-ml-2 hover:py-1 hover:pl-2 "
55
55
let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70"
56
56
57
- let rec renderNode = ( node : node , level : int ) => {
57
+ let rec renderNode = node => {
58
58
let isCurrentRoute =
59
59
Js .Array2 .joinWith (moduleRoute , "/" ) === Js .Array2 .joinWith (node .path , "/" )
60
+
60
61
let classNameActive = isCurrentRoute ? classNameActive : ""
61
62
62
63
let hasChildren = node .children -> Js .Array2 .length > 0
@@ -79,7 +80,7 @@ module SidebarTree = {
79
80
{if hasChildren {
80
81
<ul className = {"ml-5" }>
81
82
{node .children
82
- -> Js .Array2 .map (node => node -> renderNode ( level + 1 ) )
83
+ -> Js .Array2 .map (renderNode )
83
84
-> React .array }
84
85
</ul >
85
86
} else {
@@ -159,7 +160,7 @@ module SidebarTree = {
159
160
<div className = "hl-overline text-gray-80 mt-5 mb-2" > {"submodules" -> React .string } </div >
160
161
{node .children
161
162
-> Js .Array2 .sortInPlaceWith ((v1 , v2 ) => v1 .name > v2 .name ? 1 : - 1 )
162
- -> Js .Array2 .map (node => node -> renderNode ( 1 ) )
163
+ -> Js .Array2 .map (renderNode )
163
164
-> React .array }
164
165
</aside >
165
166
</div >
@@ -182,31 +183,52 @@ type api = {
182
183
type params = {slug : array <string >}
183
184
type props = result <api , string >
184
185
185
- external asMarkdownH2 : 'a => Markdown .H2 .props <string , React .element > => React .element = "%identity"
186
-
187
- external asMdxPlugin : 'a => MdxRemote .mdxPlugin = "%identity"
188
-
189
- let default = (props : props ) => {
190
- let (isSidebarOpen , setSidebarOpen ) = React .useState (_ => false )
191
- let toggleSidebar = () => setSidebarOpen (prev => ! prev )
192
- let router = Next .Router .useRouter ()
193
-
194
- let docstringsMarkdown = (~docstrings , ~slugPrefix ) => {
186
+ module MarkdownStylize = {
187
+ external asMarkdownH2 : 'a => Markdown .H2 .props <string , React .element > => React .element =
188
+ "%identity"
189
+ @react.component
190
+ let make = (~content , ~rehypePlugins : option <array <MdxRemote .mdxPlugin >>= ?) => {
195
191
let components = {
196
192
... MarkdownComponents .default ,
197
193
h2 : MarkdownComponents .default .h3 -> asMarkdownH2 ,
198
194
}
195
+ <ReactMarkdown components = {components } ?rehypePlugins > content </ReactMarkdown >
196
+ }
197
+ }
198
+
199
+ module DeprecatedMessage = {
200
+ @react.component
201
+ let make = (~deprecated ) => {
202
+ switch deprecated -> Js .Null .toOption {
203
+ | Some (content ) =>
204
+ <Markdown .Warn >
205
+ <h4 className = {"hl-4 mb-2" }> {"Deprecated" -> React .string } </h4 >
206
+ <MarkdownStylize content />
207
+ </Markdown .Warn >
208
+ | None => React .null
209
+ }
210
+ }
211
+ }
199
212
213
+ module DocstringsStylize = {
214
+ external asMdxPlugin : 'a => MdxRemote .mdxPlugin = "%identity"
215
+ @react.component
216
+ let make = (~docstrings , ~slugPrefix ) => {
200
217
let options = {"prefix" : slugPrefix ++ "-" }-> asMdxPlugin
201
- docstrings
202
- -> Js .Array2 .map (doc =>
203
- <ReactMarkdown
204
- components = {components } rehypePlugins = {[[MdxRemote .rehypeSlug , options ]-> asMdxPlugin ]}>
205
- doc
206
- </ReactMarkdown >
207
- )
208
- -> React .array
218
+ <div className = {"mt-3" }>
219
+ {docstrings
220
+ -> Js .Array2 .map (content =>
221
+ <MarkdownStylize content rehypePlugins = {[[MdxRemote .rehypeSlug , options ]-> asMdxPlugin ]} />
222
+ )
223
+ -> React .array }
224
+ </div >
209
225
}
226
+ }
227
+
228
+ let default = (props : props ) => {
229
+ let (isSidebarOpen , setSidebarOpen ) = React .useState (_ => false )
230
+ let toggleSidebar = () => setSidebarOpen (prev => ! prev )
231
+ let router = Next .Router .useRouter ()
210
232
211
233
let title = switch props {
212
234
| Ok ({module_ : {id }}) => id
@@ -219,26 +241,30 @@ let default = (props: props) => {
219
241
| Ok ({module_ : {id , name , docstrings , items }}) =>
220
242
let valuesAndType = items -> Js .Array2 .map (item => {
221
243
switch item {
222
- | Value ({name , signature , docstrings }) =>
244
+ | Value ({name , signature , docstrings , deprecated }) =>
223
245
let code = Js .String2 .replaceByRe (signature , %re ("/\\ n/g" ), "\n " )
246
+ let slugPrefix = "value-" ++ name
224
247
<>
225
- <H2 id = name > {name -> React .string } </H2 >
248
+ <H2 id = slugPrefix > {name -> React .string } </H2 >
249
+ <DeprecatedMessage deprecated />
226
250
<CodeExample code lang = "rescript" />
227
- <div className = "mt-3" > { docstringsMarkdown (~ docstrings , ~ slugPrefix = name )} </ div >
251
+ <DocstringsStylize docstrings slugPrefix / >
228
252
</>
229
- | Type ({name , signature , docstrings }) =>
253
+ | Type ({name , signature , docstrings , deprecated }) =>
230
254
let code = Js .String2 .replaceByRe (signature , %re ("/\\ n/g" ), "\n " )
255
+ let slugPrefix = "type-" ++ name
231
256
<>
232
- <H2 id = name > {name -> React .string } </H2 >
257
+ <H2 id = slugPrefix > {name -> React .string } </H2 >
258
+ <DeprecatedMessage deprecated />
233
259
<CodeExample code lang = "rescript" />
234
- <div className = { "mt-3" }> { docstringsMarkdown (~ docstrings , ~ slugPrefix = name )} </ div >
260
+ <DocstringsStylize docstrings slugPrefix / >
235
261
</>
236
262
}
237
263
})
238
264
239
265
<>
240
266
<H1 > {name -> React .string } </H1 >
241
- { docstringsMarkdown (~ docstrings , ~ slugPrefix = id )}
267
+ < DocstringsStylize docstrings slugPrefix = id />
242
268
{valuesAndType -> React .array }
243
269
</>
244
270
| _ => React .null
@@ -279,13 +305,18 @@ let default = (props: props) => {
279
305
// | _ => None
280
306
// }
281
307
308
+ let version = switch Url .parse (router .asPath ).version {
309
+ | Latest | NoVersion => "latest"
310
+ | Version (v ) => v
311
+ }
312
+
282
313
let sidebar = switch props {
283
314
| Ok ({toctree }) => <SidebarTree isOpen = isSidebarOpen toggle = toggleSidebar node = {toctree } />
284
315
| Error (_ ) => React .null
285
316
}
286
317
287
318
let prefix = {
288
- {Url .name : "API" , href : "/docs/manual/" ++ ("latest" ++ "/api" )}
319
+ {Url .name : "API" , href : "/docs/manual/" ++ (version ++ "/api" )}
289
320
}
290
321
291
322
let breadcrumbs = ApiLayout .makeBreadcrumbs (~prefix , router .asPath )
0 commit comments