Skip to content

Commit acc11cf

Browse files
Use version instead of 'latest' everywhere
1 parent 86e5206 commit acc11cf

File tree

12 files changed

+63
-72
lines changed

12 files changed

+63
-72
lines changed

src/ApiDocs.res

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ module SidebarTree = {
9191
@react.component
9292
let make = (~isOpen: bool, ~toggle: unit => unit, ~node: node, ~items: array<item>) => {
9393
let router = Next.Router.useRouter()
94+
let url = router.route->Url.parse
95+
let version = url->Url.getVersionString
9496

9597
let moduleRoute =
9698
Webapi.URL.make("file://" ++ router.asPath).pathname
97-
->String.replace("/docs/manual/latest/api/", "")
99+
->String.replace(`/docs/manual/${version}/api/`, "")
98100
->String.split("/")
99101

100102
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 "
@@ -179,10 +181,10 @@ module SidebarTree = {
179181
}
180182
let version = url->Url.getVersionString
181183
let availableVersions = switch node.name {
182-
| "Core" => [("latest", "v11.0")]
184+
| "Core" => [("latest", "v11.0.0")]
183185
| _ => ApiLayout.allApiVersions
184186
}
185-
<VersionSelect onChange version availableVersions />
187+
<VersionSelect onChange version availableVersions nextVersion=?Constants.nextVersion />
186188
| None => React.null
187189
}}
188190
</div>

src/DocsOverview.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let default = (~showVersionSelect=true) => {
2727
let ecosystem = [
2828
("Package Index", "/packages"),
2929
("rescript-react", "/docs/react/latest/introduction"),
30-
("GenType", "/docs/manual/latest/typescript-integration"),
30+
("GenType", `/docs/manual/${version}/typescript-integration`),
3131
("Reanalyze", "https://github.com/rescript-lang/reanalyze"),
3232
]
3333

@@ -50,7 +50,7 @@ let default = (~showVersionSelect=true) => {
5050
<div className="text-fire">
5151
<VersionSelect
5252
availableVersions=Constants.allManualVersions
53-
nextVersion=Constants.nextVersion
53+
nextVersion=?Constants.nextVersion
5454
onChange
5555
version
5656
/>

src/Playground.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ module Settings = {
975975
})
976976
<>
977977
<option disabled=true className="py-4">
978-
{React.string("---Experimental---")}
978+
{React.string("--- Experimental ---")}
979979
</option>
980980
{versionByOrder
981981
->Array.map(version => {
@@ -986,7 +986,7 @@ module Settings = {
986986
})
987987
->React.array}
988988
<option disabled=true className="py-4">
989-
{React.string("---Official Releases---")}
989+
{React.string("--- Official Releases ---")}
990990
</option>
991991
</>
992992
}}

src/common/App.res

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ let make = (props: props): React.element => {
5454
// landing page
5555
| {base: [], pagepath: []} => <LandingPageLayout> content </LandingPageLayout>
5656
// docs routes
57-
| {base: ["docs", "manual"], pagepath, version} =>
57+
| {base: ["docs", "manual"], pagepath} =>
5858
// check if it's an api route
5959
<EnableCollapsibleNavbar>
6060
{switch pagepath[0] {
6161
| Some("api") =>
62-
switch version {
63-
| Latest =>
62+
switch url->Url.getVersionString {
63+
| ("v11.0.0" | "v12.0.0") as version =>
6464
switch (Array.length(pagepath), pagepath[1]) {
65-
| (1, _) => <ApiOverviewLayout.Docs> content </ApiOverviewLayout.Docs>
65+
| (1, _) => <ApiOverviewLayout.Docs version> content </ApiOverviewLayout.Docs>
6666
| _ => content
6767
}
68-
| Version("v8.0.0") =>
68+
| "v8.0.0" =>
6969
switch (Array.length(pagepath), pagepath[1]) {
7070
| (1, _) => <ApiOverviewLayout8_0_0.Docs> content </ApiOverviewLayout8_0_0.Docs>
7171
| (2, Some("js")) => <JsDocsLayout8_0_0.Prose> content </JsDocsLayout8_0_0.Prose>
@@ -75,7 +75,7 @@ let make = (props: props): React.element => {
7575
| (_, Some("dom")) => <DomDocsLayout8_0_0.Docs> content </DomDocsLayout8_0_0.Docs>
7676
| _ => React.null
7777
}
78-
| Version("v9.0.0") =>
78+
| "v9.0.0" =>
7979
switch (Array.length(pagepath), pagepath[1]) {
8080
| (1, _) => <ApiOverviewLayout9_0_0.Docs> content </ApiOverviewLayout9_0_0.Docs>
8181
| (2, Some("js")) => <JsDocsLayout9_0_0.Prose> content </JsDocsLayout9_0_0.Prose>
@@ -85,7 +85,7 @@ let make = (props: props): React.element => {
8585
| (_, Some("dom")) => <DomDocsLayout9_0_0.Docs> content </DomDocsLayout9_0_0.Docs>
8686
| _ => React.null
8787
}
88-
| Version("v10.0.0") =>
88+
| "v10.0.0" =>
8989
switch (Array.length(pagepath), pagepath[1]) {
9090
| (1, _) => <ApiOverviewLayout10_0_0.Docs> content </ApiOverviewLayout10_0_0.Docs>
9191
| (2, Some("js")) => <JsDocsLayout10_0_0.Prose> content </JsDocsLayout10_0_0.Prose>
@@ -98,28 +98,24 @@ let make = (props: props): React.element => {
9898
| _ => content
9999
}
100100
| _ =>
101-
switch version {
102-
| Latest =>
103-
<ManualDocsLayout.Latest frontmatter={component->frontmatter}>
104-
content
105-
</ManualDocsLayout.Latest>
106-
| Version("v8.0.0") =>
101+
switch url->Url.getVersionString {
102+
| "v8.0.0" =>
107103
<ManualDocsLayout.V800 frontmatter={component->frontmatter}>
108104
content
109105
</ManualDocsLayout.V800>
110-
| Version("v9.0.0") =>
106+
| "v9.0.0" =>
111107
<ManualDocsLayout.V900 frontmatter={component->frontmatter}>
112108
content
113109
</ManualDocsLayout.V900>
114-
| Version("v10.0.0") =>
110+
| "v10.0.0" =>
115111
<ManualDocsLayout.V1000 frontmatter={component->frontmatter}>
116112
content
117113
</ManualDocsLayout.V1000>
118-
| Version("v11.0.0") =>
114+
| "v11.0.0" =>
119115
<ManualDocsLayout.V1100 frontmatter={component->frontmatter}>
120116
content
121117
</ManualDocsLayout.V1100>
122-
| Version("v12.0.0") =>
118+
| "v12.0.0" =>
123119
<ManualDocsLayout.V1200 frontmatter={component->frontmatter}>
124120
content
125121
</ManualDocsLayout.V1200>

src/common/Constants.res

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ type versions = {
1212

1313
// This is used for the version dropdown in the manual layouts
1414
let allManualVersions = [
15-
("latest", versions.latest),
15+
(versions.latest, versions.latest),
1616
("v10.0.0", "v9.1 - v10.1"),
1717
("v9.0.0", "v8.2 - v9.0"),
1818
("v8.0.0", "v6.0 - v8.2"),
1919
]
20-
let nextVersion = ("next", versions.next)
20+
21+
let nextVersion = versions.latest === versions.next ? None : Some(versions.next, versions.next)
2122

2223
let allReactVersions = [("latest", "v0.12.0"), ("v0.11.0", "v0.11.0"), ("v0.10.0", "v0.10.0")]
2324

@@ -31,13 +32,6 @@ let languageManual = version => {
3132
]
3233
}
3334

34-
let ecosystem = [
35-
("Package Index", "/packages"),
36-
("rescript-react", "/docs/react/latest/introduction"),
37-
("GenType", "/docs/manual/latest/typescript-integration"),
38-
("Reanalyze", "https://github.com/rescript-lang/reanalyze"),
39-
]
40-
4135
let tools = [("Syntax Lookup", "/syntax-lookup")]
4236

4337
let githubHref = "https://github.com/rescript-lang/rescript"

src/common/Url.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ let parse = (route: string): t => {
6565
(NoVersion, fullpath, [])
6666
} else {
6767
let version = switch fullpath[foundVersionIndex] {
68-
| Some("next") => Next
69-
| Some("latest") => Latest
68+
| Some(version) if version === Constants.versions.next => Next
69+
| Some(version) if version === Constants.versions.latest => Latest
7070
| Some(v) => Version(v)
7171
| None => NoVersion
7272
}
@@ -82,7 +82,7 @@ let parse = (route: string): t => {
8282

8383
let getVersionString = url =>
8484
switch url.version {
85-
| Next => "next"
86-
| Latest | NoVersion => "latest"
85+
| Next => Constants.versions.next
86+
| Latest | NoVersion => Constants.versions.latest
8787
| Version(version) => version
8888
}

src/components/Navigation.res

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module DocsSection = {
181181
imgSrc: "/static/ic_gentype@2x.png",
182182
title: "GenType",
183183
description: "Seamless TypeScript integration",
184-
href: "/docs/manual/latest/typescript-integration",
184+
href: `/docs/manual/${version}/typescript-integration`,
185185
isActive: url => {
186186
switch url.fullpath {
187187
| ["docs", "manual", _, "typescript-integration"] => true
@@ -330,20 +330,20 @@ module DocsSection = {
330330
<div className="px-4 w-full space-x-2 max-w-1280 ">
331331
<VersionSelect
332332
availableVersions=Constants.allManualVersions
333-
nextVersion=Constants.nextVersion
333+
nextVersion=?Constants.nextVersion
334334
onChange=onVersionChange
335335
version
336336
/>
337-
{switch version {
338-
| "next" =>
337+
{if version === Constants.versions.next {
339338
<span className="text-fire-50 text-12">
340339
{React.string("This docs version is work in progress!")}
341340
</span>
342-
| "latest" =>
341+
} else if version === Constants.versions.latest {
343342
<span className="text-gray-40 text-12">
344343
{React.string("This is the latest docs version")}
345344
</span>
346-
| _ => React.null
345+
} else {
346+
React.null
347347
}}
348348
</div>
349349
</div>
@@ -420,11 +420,13 @@ let make = (~fixed=true, ~isOverlayOpen: bool, ~setOverlayOpen: (bool => bool) =
420420
let minWidth = "20rem"
421421
let router = Next.Router.useRouter()
422422
let route = router.route
423+
let url = router.route->Url.parse
424+
let version = url->Url.getVersionString
423425

424426
let (collapsibles, setCollapsibles) = React.useState(_ => [
425427
{
426428
title: "Docs",
427-
href: "/docs/manual/latest/api",
429+
href: `/docs/manual/${version}/api`,
428430
isActiveRoute: route => {
429431
let url = Url.parse(route)
430432
switch url {
@@ -535,7 +537,7 @@ let make = (~fixed=true, ~isOverlayOpen: bool, ~setOverlayOpen: (bool => bool) =
535537
className="flex ml-10 space-x-5 w-full max-w-320"
536538
style={ReactDOMStyle.make(~maxWidth="26rem", ())}>
537539
{collapsibleElements->React.array}
538-
<Link href="/docs/manual/latest/api" className={linkOrActiveApiSubroute(~route)}>
540+
<Link href={`/docs/manual/${version}/api`} className={linkOrActiveApiSubroute(~route)}>
539541
{React.string("API")}
540542
</Link>
541543
<Link

src/components/VersionSelect.res

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ let make = (
1414
name="versionSelection"
1515
value=version
1616
onChange>
17-
{nextVersion->Option.isSome
18-
? <option disabled=true className="py-4"> {React.string("---Current---")} </option>
19-
: React.null}
20-
{React.array(children)}
2117
{switch nextVersion {
2218
| None => React.null
2319
| Some((value, label)) =>
2420
<>
25-
<option disabled=true className="py-4"> {React.string("---Next---")} </option>
21+
<option disabled=true key="next-heading" className="py-4">
22+
{React.string("--- Next ---")}
23+
</option>
2624
<option className="py-4" key=value value> {React.string(label)} </option>
25+
<option disabled=true key="released-heading" className="py-4">
26+
{React.string("--- Released ---")}
27+
</option>
2728
</>
2829
}}
30+
{React.array(children)}
2931
</select>
3032
}

src/layouts/ApiLayout.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ let make = (
113113
("/" ++ (version ++ ("/" ++ Array.join(url.pagepath, "/")))))
114114
router->Next.Router.push(targetUrl)
115115
}
116-
<VersionSelect onChange version availableVersions=allApiVersions />
116+
<VersionSelect
117+
onChange version availableVersions=allApiVersions nextVersion=?Constants.nextVersion
118+
/>
117119
| None => React.null
118120
}}
119121
</div>

src/layouts/ApiOverviewLayout.res

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,34 @@
11
module Sidebar = SidebarLayout.Sidebar
22

3-
let categories: array<Sidebar.Category.t> = [
3+
let makeCategories: string => array<Sidebar.Category.t> = version => [
44
{
55
name: "Introduction",
6-
items: [{name: "Overview", href: "/docs/manual/latest/api"}],
6+
items: [{name: "Overview", href: `/docs/manual/${version}/api`}],
77
},
88
{
99
name: "Standard Library",
10-
items: [{name: "Core", href: "/docs/manual/latest/api/core"}],
10+
items: [{name: "Core", href: `/docs/manual/${version}/api/core`}],
1111
},
1212
{
1313
name: "Additional Libraries",
1414
items: [
15-
{name: "Belt", href: "/docs/manual/latest/api/belt"},
16-
{name: "Dom", href: "/docs/manual/latest/api/dom"},
15+
{name: "Belt", href: `/docs/manual/${version}/api/belt`},
16+
{name: "Dom", href: `/docs/manual/${version}/api/dom`},
1717
],
1818
},
1919
{
2020
name: "Legacy Modules",
21-
items: [{name: "Js", href: "/docs/manual/latest/api/js"}],
21+
items: [{name: "Js", href: `/docs/manual/${version}/api/js`}],
2222
},
2323
]
2424

2525
/* Used for API docs (structured data) */
2626
module Docs = {
2727
@react.component
28-
let make = (~components=ApiMarkdown.default, ~children) => {
28+
let make = (~version, ~components=ApiMarkdown.default, ~children) => {
2929
let title = "API"
30-
let version = "latest"
30+
let categories = makeCategories(version)
3131

3232
<ApiLayout title categories version components> children </ApiLayout>
3333
}
3434
}
35-
36-
/*
37-
This layout is used for structured prose text with proper H2 headings.
38-
We cannot really use the same layout as with the Docs module, since they
39-
have different semantic styling and do things such as hiding the text
40-
of H2 nodes.
41-
*/
42-
/* module Prose = { */
43-
/* @react.component */
44-
/* let make = (~children) => <Docs components=Markdown.default> children </Docs> */
45-
/* } */

src/layouts/ApiOverviewLayout.resi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module Docs: {
22
@react.component
3-
let make: (~components: MarkdownComponents.t=?, ~children: React.element) => React.element
3+
let make: (
4+
~version: string,
5+
~components: MarkdownComponents.t=?,
6+
~children: React.element,
7+
) => React.element
48
}

src/layouts/DocsLayout.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ module Make = (Content: StaticContent) => {
239239
?frontmatter,
240240
?version,
241241
?availableVersions,
242-
nextVersion: Constants.nextVersion,
242+
nextVersion: ?Constants.nextVersion,
243243
?activeToc,
244244
categories,
245245
?components,

0 commit comments

Comments
 (0)