Skip to content

Commit c316edd

Browse files
committed
[refactor]: unify api docs layout
1 parent c72e414 commit c316edd

27 files changed

+454
-1627
lines changed

src/common/App.res

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,41 +59,13 @@ let make = (props: props): React.element => {
5959
switch pagepath[0] {
6060
| Some("api") =>
6161
switch url->Url.getVersionString {
62-
| ("v11.0.0" | "v12.0.0") as version =>
62+
| "v11.0.0" | "v12.0.0" =>
6363
switch (Array.length(pagepath), pagepath[1]) {
64-
| (1, _) => <ApiOverviewLayout.Docs version> content </ApiOverviewLayout.Docs>
64+
| (1, _) => <ApiOverviewLayout.Docs version=url> content </ApiOverviewLayout.Docs>
6565
| _ => content
6666
}
67-
| "v8.0.0" =>
68-
switch (Array.length(pagepath), pagepath[1]) {
69-
| (1, _) => <ApiOverviewLayout8_0_0.Docs> content </ApiOverviewLayout8_0_0.Docs>
70-
| (2, Some("js")) => <JsDocsLayout8_0_0.Prose> content </JsDocsLayout8_0_0.Prose>
71-
| (2, Some("belt")) => <BeltDocsLayout8_0_0.Prose> content </BeltDocsLayout8_0_0.Prose>
72-
| (_, Some("js")) => <JsDocsLayout8_0_0.Docs> content </JsDocsLayout8_0_0.Docs>
73-
| (_, Some("belt")) => <BeltDocsLayout8_0_0.Docs> content </BeltDocsLayout8_0_0.Docs>
74-
| (_, Some("dom")) => <DomDocsLayout8_0_0.Docs> content </DomDocsLayout8_0_0.Docs>
75-
| _ => React.null
76-
}
77-
| "v9.0.0" =>
78-
switch (Array.length(pagepath), pagepath[1]) {
79-
| (1, _) => <ApiOverviewLayout9_0_0.Docs> content </ApiOverviewLayout9_0_0.Docs>
80-
| (2, Some("js")) => <JsDocsLayout9_0_0.Prose> content </JsDocsLayout9_0_0.Prose>
81-
| (2, Some("belt")) => <BeltDocsLayout9_0_0.Prose> content </BeltDocsLayout9_0_0.Prose>
82-
| (_, Some("js")) => <JsDocsLayout9_0_0.Docs> content </JsDocsLayout9_0_0.Docs>
83-
| (_, Some("belt")) => <BeltDocsLayout9_0_0.Docs> content </BeltDocsLayout9_0_0.Docs>
84-
| (_, Some("dom")) => <DomDocsLayout9_0_0.Docs> content </DomDocsLayout9_0_0.Docs>
85-
| _ => React.null
86-
}
87-
| "v10.0.0" =>
88-
switch (Array.length(pagepath), pagepath[1]) {
89-
| (1, _) => <ApiOverviewLayout10_0_0.Docs> content </ApiOverviewLayout10_0_0.Docs>
90-
| (2, Some("js")) => <JsDocsLayout10_0_0.Prose> content </JsDocsLayout10_0_0.Prose>
91-
| (2, Some("belt")) => <BeltDocsLayout10_0_0.Prose> content </BeltDocsLayout10_0_0.Prose>
92-
| (_, Some("js")) => <JsDocsLayout10_0_0.Docs> content </JsDocsLayout10_0_0.Docs>
93-
| (_, Some("belt")) => <BeltDocsLayout10_0_0.Docs> content </BeltDocsLayout10_0_0.Docs>
94-
| (_, Some("dom")) => <DomDocsLayout10_0_0.Docs> content </DomDocsLayout10_0_0.Docs>
95-
| _ => React.null
96-
}
67+
| "v8.0.0" | "v9.0.0" | "v10.0.0" =>
68+
<ApiOverviewLayoutLegacy version=url> content </ApiOverviewLayoutLegacy>
9769
| _ => content
9870
}
9971
| _ =>

src/layouts/ApiOverviewLayout.res

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
module Sidebar = SidebarLayout.Sidebar
22

3-
let makeCategories: string => array<Sidebar.Category.t> = version => [
4-
{
5-
name: "Overview",
6-
items: [
7-
{name: "Introduction", href: `/docs/manual/${version}/api`},
8-
if version >= "v12.0.0" {
9-
{name: "Stdlib", href: `/docs/manual/${version}/api/stdlib`}
10-
} else {
11-
{name: "Core", href: `/docs/manual/${version}/api/core`}
3+
let makeCategories: Url.t => array<Sidebar.Category.t> = url => {
4+
switch url.version {
5+
| Version("v12.0.0" | "v11.0.0") | Latest | Next =>
6+
let version = Url.getVersionString(url)
7+
[
8+
{
9+
name: "Overview",
10+
items: [
11+
{name: "Introduction", href: `/docs/manual/${version}/api`},
12+
if version >= "v12.0.0" {
13+
{name: "Stdlib", href: `/docs/manual/${version}/api/stdlib`}
14+
} else {
15+
{name: "Core", href: `/docs/manual/${version}/api/core`}
16+
},
17+
],
1218
},
13-
],
14-
},
15-
{
16-
name: "Additional Libraries",
17-
items: [
18-
{name: "Belt", href: `/docs/manual/${version}/api/belt`},
19-
{name: "Dom", href: `/docs/manual/${version}/api/dom`},
20-
],
21-
},
22-
]
19+
{
20+
name: "Additional Libraries",
21+
items: [
22+
{name: "Belt", href: `/docs/manual/${version}/api/belt`},
23+
{name: "Dom", href: `/docs/manual/${version}/api/dom`},
24+
],
25+
},
26+
]
27+
| _ => throw(Failure(`Invalid version ${url->Url.getVersionString}`))
28+
}
29+
}
2330

2431
/* Used for API docs (structured data) */
2532
module Docs = {
2633
@react.component
2734
let make = (~version, ~components=ApiMarkdown.default, ~children) => {
35+
let router = Next.Router.useRouter()
36+
let route = router.route
37+
2838
let categories = makeCategories(version)
39+
let versionStr = Url.getVersionString(version)
2940

30-
<ApiLayout categories version components> children </ApiLayout>
41+
<ApiLayout categories version=versionStr components>
42+
{switch version.version {
43+
| Version("v9.0.0" | "v8.0.0") => <ApiLayout.OldDocsWarning route version=versionStr />
44+
| _ => React.null
45+
}}
46+
children
47+
</ApiLayout>
3148
}
3249
}

src/layouts/ApiOverviewLayout.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Docs: {
22
@react.component
33
let make: (
4-
~version: string,
4+
~version: Url.t,
55
~components: MarkdownComponents.t=?,
66
~children: React.element,
77
) => React.element

src/layouts/ApiOverviewLayout10_0_0.res

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/layouts/ApiOverviewLayout10_0_0.resi

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/layouts/ApiOverviewLayout8_0_0.res

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/layouts/ApiOverviewLayout8_0_0.resi

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/layouts/ApiOverviewLayout9_0_0.res

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/layouts/ApiOverviewLayout9_0_0.resi

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)