Skip to content

[refactor]: unify api docs layout #1062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
version as string
  • Loading branch information
aspeddro committed Jun 30, 2025
commit 1a70252415370e789ce4db9ebded9d1711582cad
8 changes: 4 additions & 4 deletions src/common/App.res
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ let make = (props: props): React.element => {
switch pagepath[0] {
| Some("api") =>
switch url->Url.getVersionString {
| "v11.0.0" | "v12.0.0" =>
| ("v11.0.0" | "v12.0.0") as version =>
switch (Array.length(pagepath), pagepath[1]) {
| (1, _) => <ApiOverviewLayout.Docs version=url> content </ApiOverviewLayout.Docs>
| (1, _) => <ApiOverviewLayout.Docs version> content </ApiOverviewLayout.Docs>
| _ => content
}
| "v8.0.0" | "v9.0.0" | "v10.0.0" =>
<ApiOverviewLayoutLegacy version=url> content </ApiOverviewLayoutLegacy>
| ("v8.0.0" | "v9.0.0" | "v10.0.0") as version =>
<ApiOverviewLayoutLegacy version> content </ApiOverviewLayoutLegacy>
| _ => content
}
| _ =>
Expand Down
54 changes: 24 additions & 30 deletions src/layouts/ApiOverviewLayout.res
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
module Sidebar = SidebarLayout.Sidebar

let makeCategories: Url.t => array<Sidebar.Category.t> = url => {
switch url.version {
| Version("v12.0.0" | "v11.0.0") | Latest | Next =>
let version = Url.getVersionString(url)
[
{
name: "Overview",
items: [
{name: "Introduction", href: `/docs/manual/${version}/api`},
if version >= "v12.0.0" {
{name: "Stdlib", href: `/docs/manual/${version}/api/stdlib`}
} else {
{name: "Core", href: `/docs/manual/${version}/api/core`}
},
],
},
{
name: "Additional Libraries",
items: [
{name: "Belt", href: `/docs/manual/${version}/api/belt`},
{name: "Dom", href: `/docs/manual/${version}/api/dom`},
],
},
]
| _ => throw(Failure(`Invalid version ${url->Url.getVersionString}`))
}
let makeCategories: string => array<Sidebar.Category.t> = version => {
[
{
name: "Overview",
items: [
{name: "Introduction", href: `/docs/manual/${version}/api`},
if version >= "v12.0.0" {
{name: "Stdlib", href: `/docs/manual/${version}/api/stdlib`}
} else {
{name: "Core", href: `/docs/manual/${version}/api/core`}
},
],
},
{
name: "Additional Libraries",
items: [
{name: "Belt", href: `/docs/manual/${version}/api/belt`},
{name: "Dom", href: `/docs/manual/${version}/api/dom`},
],
},
]
}

/* Used for API docs (structured data) */
Expand All @@ -36,11 +31,10 @@ module Docs = {
let route = router.route

let categories = makeCategories(version)
let versionStr = Url.getVersionString(version)

<ApiLayout categories version=versionStr components>
{switch version.version {
| Version("v9.0.0" | "v8.0.0") => <ApiLayout.OldDocsWarning route version=versionStr />
<ApiLayout categories version components>
{switch version {
| "v9.0.0" | "v8.0.0" => <ApiLayout.OldDocsWarning route version />
| _ => React.null
}}
children
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/ApiOverviewLayout.resi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Docs: {
@react.component
let make: (
~version: Url.t,
~version: string,
~components: MarkdownComponents.t=?,
~children: React.element,
) => React.element
Expand Down
12 changes: 7 additions & 5 deletions src/layouts/ApiOverviewLayoutLegacy.res
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,16 @@ let moduleCategories = (moduleName, version) => {
}

@react.component
let make = (~components=ApiMarkdown.default, ~version: Url.t, ~children) => {
let make = (~components=ApiMarkdown.default, ~version, ~children) => {
let router = Next.Router.useRouter()
let route = router.route
let versionStr = version->Url.getVersionString
let url = router.route->Url.parse

let versionStr = version

let warnBanner = <ApiLayout.OldDocsWarning route version=versionStr />

switch version.pagepath->Array.get(1) {
switch url.pagepath->Array.get(1) {
| None =>
let title = "API"
let categories: array<Category.t> = [
Expand All @@ -348,7 +350,7 @@ let make = (~components=ApiMarkdown.default, ~version: Url.t, ~children) => {
name: "Modules",
items: [
{name: "Js Module", href: `/docs/manual/${versionStr}/api/js`},
{name: "Belt Stdlib", href: `/docs/manual/${versionStr}/api/belt`},
{name: "Belt Module", href: `/docs/manual/${versionStr}/api/belt`},
{name: "Dom Module", href: `/docs/manual/${versionStr}/api/dom`},
],
},
Expand All @@ -360,7 +362,7 @@ let make = (~components=ApiMarkdown.default, ~version: Url.t, ~children) => {
| Some(moduleName) =>
let indexData = switch Dict.get(indexData, moduleName) {
| Some(moduleData) =>
Dict.get(moduleData, version->Url.getVersionString)->Option.getOrThrow(
Dict.get(moduleData, version)->Option.getOrThrow(
~message=`Not found data for ${moduleName} version ${versionStr}`,
)
| None => throw(Failure(`Not found index data for module: ${moduleName}`))
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/ApiOverviewLayoutLegacy.resi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@react.component
let make: (
~components: MarkdownComponents.t=?,
~version: Url.t,
~version: string,
~children: React.element,
) => React.element