Skip to content

Commit 165aba1

Browse files
committed
remove some layouts
1 parent 6195d85 commit 165aba1

File tree

12 files changed

+247
-636
lines changed

12 files changed

+247
-636
lines changed

data/api/latest/belt.json

Lines changed: 52 additions & 50 deletions
Large diffs are not rendered by default.

data/api/latest/js.json

Lines changed: 89 additions & 58 deletions
Large diffs are not rendered by default.

scripts/gendocs.res

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let dirVersion = Path.join([dirname, "..", "data", "api", version])
3737

3838
if Fs.existsSync(dirVersion) {
3939
Js.Console.error(`Directory ${dirVersion} already exists`)
40-
Process.exit(1)
40+
// Process.exit(1)
4141
} else {
4242
Fs.mkdirSync(dirVersion)
4343
}
@@ -110,25 +110,39 @@ let allModules = {
110110
open Js.Json
111111
let encodeItem = (docItem: Docgen.item) => {
112112
switch docItem {
113-
| Value({id, name, docstrings, signature}) => {
114-
let dict = Js.Dict.fromArray([
113+
| Value({id, name, docstrings, signature, ?deprecated}) => {
114+
let dict = Js.Dict.fromArray(
115+
[
116+
("id", id->string),
117+
("kind", "value"->string),
118+
("name", name->string),
119+
("docstrings", docstrings->stringArray),
120+
("signature", signature->string),
121+
]->Js.Array2.concat(
122+
switch deprecated {
123+
| Some(v) => [("deprecated", v->string)]
124+
| None => []
125+
},
126+
),
127+
)
128+
dict->object_->Some
129+
}
130+
131+
| Type({id, name, docstrings, signature, ?deprecated}) =>
132+
let dict = Js.Dict.fromArray(
133+
[
115134
("id", id->string),
116-
("kind", "value"->string),
135+
("kind", "type"->string),
117136
("name", name->string),
118137
("docstrings", docstrings->stringArray),
119138
("signature", signature->string),
120-
])
121-
dict->object_->Some
122-
}
123-
124-
| Type({id, name, docstrings, signature}) =>
125-
let dict = Js.Dict.fromArray([
126-
("id", id->string),
127-
("kind", "type"->string),
128-
("name", name->string),
129-
("docstrings", docstrings->stringArray),
130-
("signature", signature->string),
131-
])
139+
]->Js.Array2.concat(
140+
switch deprecated {
141+
| Some(v) => [("deprecated", v->string)]
142+
| None => []
143+
},
144+
),
145+
)
132146
object_(dict)->Some
133147

134148
| _ => None

src/ApiDocs.res

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ module SidebarTree = {
5454
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 "
5555
let classNameActive = " bg-fire-5 text-red-500 -ml-2 pl-2 font-medium hover:bg-fire-70"
5656

57-
let rec renderNode = (node: node, level: int) => {
57+
let rec renderNode = node => {
5858
let isCurrentRoute =
5959
Js.Array2.joinWith(moduleRoute, "/") === Js.Array2.joinWith(node.path, "/")
60+
6061
let classNameActive = isCurrentRoute ? classNameActive : ""
6162

6263
let hasChildren = node.children->Js.Array2.length > 0
@@ -79,7 +80,7 @@ module SidebarTree = {
7980
{if hasChildren {
8081
<ul className={"ml-5"}>
8182
{node.children
82-
->Js.Array2.map(node => node->renderNode(level + 1))
83+
->Js.Array2.map(renderNode)
8384
->React.array}
8485
</ul>
8586
} else {
@@ -159,7 +160,7 @@ module SidebarTree = {
159160
<div className="hl-overline text-gray-80 mt-5 mb-2"> {"submodules"->React.string} </div>
160161
{node.children
161162
->Js.Array2.sortInPlaceWith((v1, v2) => v1.name > v2.name ? 1 : -1)
162-
->Js.Array2.map(node => node->renderNode(1))
163+
->Js.Array2.map(renderNode)
163164
->React.array}
164165
</aside>
165166
</div>
@@ -182,31 +183,52 @@ type api = {
182183
type params = {slug: array<string>}
183184
type props = result<api, string>
184185

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>>=?) => {
195191
let components = {
196192
...MarkdownComponents.default,
197193
h2: MarkdownComponents.default.h3->asMarkdownH2,
198194
}
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+
}
199212

213+
module DocstringsStylize = {
214+
external asMdxPlugin: 'a => MdxRemote.mdxPlugin = "%identity"
215+
@react.component
216+
let make = (~docstrings, ~slugPrefix) => {
200217
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>
209225
}
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()
210232

211233
let title = switch props {
212234
| Ok({module_: {id}}) => id
@@ -219,26 +241,30 @@ let default = (props: props) => {
219241
| Ok({module_: {id, name, docstrings, items}}) =>
220242
let valuesAndType = items->Js.Array2.map(item => {
221243
switch item {
222-
| Value({name, signature, docstrings}) =>
244+
| Value({name, signature, docstrings, deprecated}) =>
223245
let code = Js.String2.replaceByRe(signature, %re("/\\n/g"), "\n")
246+
let slugPrefix = "value-" ++ name
224247
<>
225-
<H2 id=name> {name->React.string} </H2>
248+
<H2 id=slugPrefix> {name->React.string} </H2>
249+
<DeprecatedMessage deprecated />
226250
<CodeExample code lang="rescript" />
227-
<div className="mt-3"> {docstringsMarkdown(~docstrings, ~slugPrefix=name)} </div>
251+
<DocstringsStylize docstrings slugPrefix />
228252
</>
229-
| Type({name, signature, docstrings}) =>
253+
| Type({name, signature, docstrings, deprecated}) =>
230254
let code = Js.String2.replaceByRe(signature, %re("/\\n/g"), "\n")
255+
let slugPrefix = "type-" ++ name
231256
<>
232-
<H2 id=name> {name->React.string} </H2>
257+
<H2 id=slugPrefix> {name->React.string} </H2>
258+
<DeprecatedMessage deprecated />
233259
<CodeExample code lang="rescript" />
234-
<div className={"mt-3"}> {docstringsMarkdown(~docstrings, ~slugPrefix=name)} </div>
260+
<DocstringsStylize docstrings slugPrefix />
235261
</>
236262
}
237263
})
238264

239265
<>
240266
<H1> {name->React.string} </H1>
241-
{docstringsMarkdown(~docstrings, ~slugPrefix=id)}
267+
<DocstringsStylize docstrings slugPrefix=id />
242268
{valuesAndType->React.array}
243269
</>
244270
| _ => React.null
@@ -279,13 +305,18 @@ let default = (props: props) => {
279305
// | _ => None
280306
// }
281307

308+
let version = switch Url.parse(router.asPath).version {
309+
| Latest | NoVersion => "latest"
310+
| Version(v) => v
311+
}
312+
282313
let sidebar = switch props {
283314
| Ok({toctree}) => <SidebarTree isOpen=isSidebarOpen toggle=toggleSidebar node={toctree} />
284315
| Error(_) => React.null
285316
}
286317

287318
let prefix = {
288-
{Url.name: "API", href: "/docs/manual/" ++ ("latest" ++ "/api")}
319+
{Url.name: "API", href: "/docs/manual/" ++ (version ++ "/api")}
289320
}
290321

291322
let breadcrumbs = ApiLayout.makeBreadcrumbs(~prefix, router.asPath)

src/ApiDocs.resi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type params = {slug: array<string>}
2+
type props
3+
4+
let default: props => React.element
5+
6+
let getStaticPropsByVersion: {"params": params, "version": string} => promise<{"props": props}>
7+
8+
let getStaticPathsByVersion: (
9+
~version: string,
10+
) => promise<{
11+
"fallback": bool,
12+
"paths": Js.Array2.t<{
13+
"params": {"slug": array<Js.String2.t>},
14+
}>,
15+
}>

src/common/App.res

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ let make = (props: props): React.element => {
4949
let content = React.createElement(component, pageProps)
5050

5151
let url = router.route->Url.parse
52+
5253
switch url {
5354
// landing page
5455
| {base: [], pagepath: []} => <LandingPageLayout> content </LandingPageLayout>
@@ -116,8 +117,6 @@ let make = (props: props): React.element => {
116117
| _ => React.null
117118
}
118119
}
119-
| {base: ["docs", "api", _]} => // Js.log(url)
120-
content
121120
| {base: ["docs", "react"], version} =>
122121
switch version {
123122
| Latest =>

0 commit comments

Comments
 (0)