Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
763ce41
[Old docs] version 8.0.0
chenglou Aug 21, 2020
53df907
[Old Docs] Beginning converting old docs back to old reason syntax
chenglou Aug 21, 2020
06eb133
[Old docs] Old reserved words
chenglou Aug 21, 2020
69727d9
[Old docs] Unused page
chenglou Aug 21, 2020
5ee43f8
[Old docs] Remove another invalid page
chenglou Aug 21, 2020
9dc2061
[Old docs] Old generic syntax
chenglou Aug 21, 2020
4da3b27
[Old docs] Convert more generics back to old syntax
chenglou Aug 21, 2020
acff0e7
[Old docs] Finish type page
chenglou Aug 21, 2020
0cad7f3
[Old docs] Finish tuple page
chenglou Aug 21, 2020
52cb0f1
[Old docs] Extension changes
chenglou Aug 21, 2020
8c2effd
[Old docs] Move 8.0.0 folder to v8.0.0
chenglou Aug 21, 2020
e491e4b
[Old docs] Sidebar
chenglou Aug 21, 2020
25323c8
[Old docs] Remove unused page
chenglou Aug 21, 2020
162aae7
[Old docs] Finish array-and-list
chenglou Aug 21, 2020
e20fe65
[Old docs] Convert @bs attributes back to old syntax
chenglou Aug 21, 2020
9aec6c7
[Old docs] bind-to-global-js-values old syntax
chenglou Aug 21, 2020
c0dde48
[Old docs] Bring master overview fix here
chenglou Aug 21, 2020
6abe8aa
[Old docs] bind-to-js-function done
chenglou Aug 21, 2020
2026254
[Old docs] Make sidebar links go to correct version
chenglou Aug 21, 2020
9831491
[Old docs] Fix type.mdx array syntax
chenglou Aug 21, 2020
868c4e3
[Old docs] bind-to-js-object
chenglou Aug 21, 2020
3acac3a
[Old doc] control flow
chenglou Aug 21, 2020
a552b7a
[Old docs] try
chenglou Aug 21, 2020
6ac96a7
[Old docs] Converting-from-js
chenglou Aug 21, 2020
9fd3e72
[Old docs] embed-raw-javascript
chenglou Aug 21, 2020
f56c4d7
[Old docs] exception
chenglou Aug 21, 2020
eca80aa
[Old docs] Update a few more pages
chenglou Aug 21, 2020
da4337a
[Old docs] Convert a few more pages
chenglou Aug 21, 2020
3ef4c0b
[Old docs] function
chenglou Aug 21, 2020
1f6c4fb
[Old docs] jsx and overview
chenglou Aug 21, 2020
89ed176
[Old docs] Mutation
chenglou Aug 21, 2020
63b35d6
[Old docs] Pattern-matching-destructuring
chenglou Aug 21, 2020
9518252
[Old docs] Module
chenglou Aug 21, 2020
9d8b35c
[Old docs] pipe
chenglou Aug 21, 2020
b71b9cf
[Old docs] Primitive types
chenglou Aug 21, 2020
acefb1b
[Old docs] newcomer-examples and promise
chenglou Aug 21, 2020
937eb37
[Old docs] More pages
chenglou Aug 21, 2020
e0a0549
[Old docs] Last few pages
chenglou Aug 21, 2020
6b9d88c
[Old docs] Relative links
chenglou Aug 21, 2020
05e940a
Add frontmatters to v8.0.0 manual pages
ryyppy Aug 21, 2020
029abbb
Add rei / resi aliases to appropriate hljs plugins
ryyppy Aug 21, 2020
bfc905a
Add frontmatter parsing support and enable frontmatter based Meta inj…
ryyppy Aug 21, 2020
14923fc
Adapt toc extracting to account frontmatter syntax
ryyppy Aug 21, 2020
770cda9
Remove ReasonCompiler toc generation
ryyppy Aug 21, 2020
3c11480
[Old docs] Change tab label from rescript to reason (old syntax)
chenglou Aug 21, 2020
25fc0a8
Add version toggle for docs layout
ryyppy Aug 21, 2020
00472df
Add router push binding
ryyppy Aug 21, 2020
2534a7f
Merge upstream
ryyppy Aug 21, 2020
4812468
Add back reason compiler toc generation
ryyppy Aug 21, 2020
c539dd2
Merge branch 'master' into 800
ryyppy Aug 21, 2020
38481f2
Fix typos
chenglou Aug 22, 2020
3d3ce8d
Rename document back
chenglou Aug 22, 2020
50a7e5b
Change url format of canonical urls (remove https://rescript-lang.org/)
ryyppy Aug 23, 2020
eb904e3
Add latestVersionLabel parameter for VesionSelect component
ryyppy Aug 23, 2020
673043a
Add use-illegal-identifier-names for v8.0.0
ryyppy Aug 23, 2020
cfb9ea8
Add frontmatter for latest manual
ryyppy Aug 23, 2020
5d867e4
Enable frontmatter for latest manual layout
ryyppy Aug 23, 2020
13f18e9
Fix link in v8 manual layout
ryyppy Aug 23, 2020
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
2 changes: 2 additions & 0 deletions bindings/Next.re
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ module Router = {
events: Events.t,
};

[@bs.send] external push: (router, string ) => unit = "push";

[@bs.module "next/router"] external useRouter: unit => router = "useRouter";
};

Expand Down
18 changes: 16 additions & 2 deletions common/App.re
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type props = {
"pageProps": pageProps,
};

[@bs.get]
external frontmatter: React.component(Js.t({.})) => Js.Json.t =
"frontmatter";

let default = (props: props): React.element => {
let component = props##"Component";
let pageProps = props##pageProps;
Expand All @@ -54,8 +58,18 @@ let default = (props: props): React.element => {

switch (url) {
// docs routes
| {base: [|"docs", "manual"|], version: Latest} =>
<ManualDocsLayout.Prose> content </ManualDocsLayout.Prose>
| {base: [|"docs", "manual"|], version} =>
switch (version) {
| Latest =>
<ManualDocsLayout.Prose frontmatter={component->frontmatter}>
content
</ManualDocsLayout.Prose>
| Version("v8.0.0") =>
<ManualDocsLayout8_0_0.Prose frontmatter={component->frontmatter}>
content
</ManualDocsLayout8_0_0.Prose>
| _ => React.null
}
| {base: [|"docs", "reason-compiler"|], version: Latest} =>
<ReasonCompilerDocsLayout> content </ReasonCompilerDocsLayout>
| {base: [|"docs", "reason-react"|], version: Latest} =>
Expand Down
20 changes: 20 additions & 0 deletions common/DocFrontmatter.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type t = {
title: string,
description: Js.null(string),
canonical: Js.null(string),
};

let decode = (json): result(t, string) => {
open! Json.Decode;
try(
Ok({
title: field("title", string, json),
description:
optional(field("description", string), json)->Js.Null.fromOption,
canonical:
optional(field("canonical", string), json)->Js.Null.fromOption,
})
) {
| DecodeError(errMsg) => Error(errMsg)
};
};
71 changes: 70 additions & 1 deletion layouts/DocsLayout.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,33 @@ module Toc = {
};
};

module VersionSelect = {
[@react.component]
let make =
(
~onChange,
~version: string,
~latestVersionLabel: string,
~availableVersions: array(string),
) => {
let children =
Belt.Array.map(
availableVersions,
ver => {
let label = ver === "latest" ? latestVersionLabel : ver;
<option className="py-4" key=ver value=ver> label->s </option>;
},
);
<select
className="text-14 border border-fire inline-block rounded px-4 py-1 font-semibold "
name="versionSelection"
value=version
onChange>
children->ate
</select>;
};
};

module Sidebar = {
module Title = {
[@react.component]
Expand Down Expand Up @@ -309,7 +336,10 @@ let make =
(
~breadcrumbs: option(list(UrlPath.breadcrumb))=?,
~title: string,
~frontmatter: option(Js.Json.t)=?,
~version: option(string)=?,
~availableVersions: option(array(string))=?,
~latestVersionLabel: string="latest",
~activeToc: option(Toc.t)=?,
~categories: array(Category.t),
~components=Markdown.default,
Expand Down Expand Up @@ -350,7 +380,31 @@ let make =
title->s
{switch (version) {
| Some(version) =>
<span className="font-mono text-sm"> version->s </span>
switch (availableVersions) {
| Some(availableVersions) =>
let onChange = evt => {
open Url;
ReactEvent.Form.preventDefault(evt);
let version = evt->ReactEvent.Form.target##value;
let url = Url.parse(route);

let targetUrl =
"/"
++ Js.Array2.joinWith(url.base, "/")
++ "/"
++ version
++ "/"
++ Js.Array2.joinWith(url.pagepath, "/");
router->Next.Router.push(targetUrl);
};
<VersionSelect
latestVersionLabel
onChange
version
availableVersions
/>;
| None => <span className="font-mono text-sm"> version->s </span>
}
| None => React.null
}}
</div>;
Expand All @@ -368,13 +422,28 @@ let make =

let metaTitle = title ++ " | ReScript Documentation";

let metaElement =
switch (frontmatter) {
| Some(frontmatter) =>
switch (DocFrontmatter.decode(frontmatter)) {
| Ok(fm) =>
let canonical = Js.Null.toOption(fm.canonical);
let description = Js.Null.toOption(fm.description);
let title = fm.title ++ " | ReScript Language Manual";
<Meta title ?description ?canonical />;
| Error(_) => React.null
}
| None => React.null
};

<SidebarLayout
metaTitle
theme
components
sidebarState=(isSidebarOpen, setSidebarOpen)
sidebar
?breadcrumbs>
metaElement
children
</SidebarLayout>;
};
85 changes: 57 additions & 28 deletions layouts/ManualDocsLayout.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
let version = "v8.2.0";

module Link = Next.Link;

// This is used for the version dropdown in the manual layouts
let allManualVersions = [|"latest", "v8.0.0"|];

// Used for replacing "latest" with "vX.X.X" in the version dropdown
let latestVersionLabel = "v8.2.0";

// Structure defined by `scripts/extract-tocs.js`
let tocData:
Js.Dict.t({
Expand All @@ -24,7 +28,10 @@ module Toc = DocsLayout.Toc;

let overviewNavs = [|
NavItem.{name: "Introduction", href: "/docs/manual/latest/introduction"},
{name: "Migrate from BuckleScript/Reason", href: "/docs/manual/latest/migrate-from-bucklescript-reason"},
{
name: "Migrate from BuckleScript/Reason",
href: "/docs/manual/latest/migrate-from-bucklescript-reason",
},
{name: "Installation", href: "/docs/manual/latest/installation"},
{name: "Try", href: "/docs/manual/latest/try"},
{name: "Editor Plugins", href: "/docs/manual/latest/editor-plugins"},
Expand All @@ -47,7 +54,10 @@ let basicNavs = [|
{name: "Function", href: "/docs/manual/latest/function"},
{name: "Control Flow", href: "/docs/manual/latest/control-flow"},
{name: "Pipe", href: "/docs/manual/latest/pipe"},
{name: "Pattern Matching/Destructuring", href: "/docs/manual/latest/pattern-matching-destructuring"},
{
name: "Pattern Matching/Destructuring",
href: "/docs/manual/latest/pattern-matching-destructuring",
},
{name: "Mutation", href: "/docs/manual/latest/mutation"},
{name: "JSX", href: "/docs/manual/latest/jsx"},
{name: "External", href: "/docs/manual/latest/external"},
Expand All @@ -60,22 +70,13 @@ let basicNavs = [|
|];

let buildsystemNavs = [|
NavItem.{
name: "Overview",
href: "/docs/manual/latest/build-overview",
},
{
name: "Configuration",
href: "/docs/manual/latest/build-configuration",
},
NavItem.{name: "Overview", href: "/docs/manual/latest/build-overview"},
{name: "Configuration", href: "/docs/manual/latest/build-configuration"},
{
name: "Interop with JS Build System",
href: "/docs/manual/latest/interop-with-js-build-systems",
},
{
name: "Performance",
href: "/docs/manual/latest/build-performance",
},
{name: "Performance", href: "/docs/manual/latest/build-performance"},
|];

let jsInteropNavs = [|
Expand All @@ -85,13 +86,31 @@ let jsInteropNavs = [|
},
{name: "Shared Data Types", href: "/docs/manual/latest/shared-data-types"},
{name: "Bind to JS Object", href: "/docs/manual/latest/bind-to-js-object"},
{name: "Bind to JS Function", href: "/docs/manual/latest/bind-to-js-function"},
{name: "Import from/Export to JS", href: "/docs/manual/latest/import-from-export-to-js"},
{name: "Bind to Global JS Values", href: "/docs/manual/latest/bind-to-global-js-values"},
{
name: "Bind to JS Function",
href: "/docs/manual/latest/bind-to-js-function",
},
{
name: "Import from/Export to JS",
href: "/docs/manual/latest/import-from-export-to-js",
},
{
name: "Bind to Global JS Values",
href: "/docs/manual/latest/bind-to-global-js-values",
},
{name: "JSON", href: "/docs/manual/latest/json"},
{name: "Use Illegal Identifier Names", href: "/docs/manual/latest/use-illegal-identifier-names"},
{name: "Browser Support & Polyfills", href: "/docs/manual/latest/browser-support-polyfills"},
{name: "Interop Cheatsheet", href: "/docs/manual/latest/interop-cheatsheet"},
{
name: "Use Illegal Identifier Names",
href: "/docs/manual/latest/use-illegal-identifier-names",
},
{
name: "Browser Support & Polyfills",
href: "/docs/manual/latest/browser-support-polyfills",
},
{
name: "Interop Cheatsheet",
href: "/docs/manual/latest/interop-cheatsheet",
},
|];

let guidesNavs = [|
Expand All @@ -103,7 +122,10 @@ let guidesNavs = [|
|];

let extraNavs = [|
NavItem.{name: "Newcomer Examples", href: "/docs/manual/latest/newcomer-examples"},
NavItem.{
name: "Newcomer Examples",
href: "/docs/manual/latest/newcomer-examples",
},
{name: "Project Structure", href: "/docs/manual/latest/project-structure"},
{name: "FAQ", href: "/docs/manual/latest/faq"},
|];
Expand All @@ -119,7 +141,12 @@ let categories = [|

module Docs = {
[@react.component]
let make = (~components=Markdown.default, ~children) => {
let make =
(
~frontmatter: option(Js.Json.t)=?,
~components=Markdown.default,
~children,
) => {
let router = Next.Router.useRouter();
let route = router.route;

Expand Down Expand Up @@ -156,13 +183,17 @@ module Docs = {
);

let title = "Language Manual";
let version = "latest";

<DocsLayout
theme=`Reason
components
categories
version
title
availableVersions=allManualVersions
latestVersionLabel
?frontmatter
?activeToc
?breadcrumbs>
children
Expand All @@ -172,9 +203,7 @@ module Docs = {

module Prose = {
[@react.component]
let make = (~children) => {
<Docs components=Markdown.default>
children
</Docs>;
let make = (~frontmatter: option(Js.Json.t)=?, ~children) => {
<Docs ?frontmatter components=Markdown.default> children </Docs>;
};
};
Loading