Skip to content

Commit efd5169

Browse files
committed
Add scaffold for React doc pages & layout
1 parent a41b05a commit efd5169

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

common/App.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ let default = (props: props): React.element => {
112112
}
113113
| {base: [|"docs", "reason-compiler"|], version: Latest} =>
114114
<ReasonCompilerDocsLayout> content </ReasonCompilerDocsLayout>
115+
| {base: [|"docs", "react"|], version: Latest} =>
116+
<ReactDocsLayout frontmatter={component->frontmatter}>
117+
content
118+
</ReactDocsLayout>
115119
| {base: [|"docs", "gentype"|], version: Latest} =>
116120
<GenTypeDocsLayout> content </GenTypeDocsLayout>
117121
// common routes

layouts/ReactDocsLayout.re

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
module Link = Next.Link;
2+
3+
module NavItem = SidebarLayout.Sidebar.NavItem;
4+
module Category = SidebarLayout.Sidebar.Category;
5+
module Toc = SidebarLayout.Toc;
6+
7+
let overviewNavs = [|
8+
{NavItem.name: "Introduction", href: "/docs/react/latest/introduction"},
9+
|];
10+
11+
module CategoryDocsLayout =
12+
// Structure defined by `scripts/extract-tocs.js`
13+
DocsLayout.Make({
14+
/*let categories = [|Category.{name: "Overview", items: overviewNavs}|];*/
15+
let tocData: SidebarLayout.Toc.raw = [%raw
16+
"require('../index_data/react_latest_toc.json')"
17+
];
18+
});
19+
20+
[@react.component]
21+
let make = (~frontmatter: option(Js.Json.t)=?, ~components=Markdown.default, ~children) => {
22+
let router = Next.Router.useRouter();
23+
let route = router.route;
24+
25+
let url = route->Url.parse;
26+
27+
let version =
28+
switch (url.version) {
29+
| Version(version) => version
30+
| NoVersion => "latest"
31+
| Latest => "latest"
32+
};
33+
34+
let prefix = [
35+
Url.{name: "Docs", href: "/docs/latest"},
36+
Url.{
37+
name: "ReasonReact",
38+
href: "/docs/react/" ++ version ++ "/introduction",
39+
},
40+
];
41+
42+
let breadcrumbs =
43+
Belt.List.concat(
44+
prefix,
45+
DocsLayout.makeBreadcrumbs(
46+
~basePath="/docs/gentype/" ++ version,
47+
route,
48+
),
49+
);
50+
51+
let title = "ReasonReact";
52+
53+
let availableVersions = [|"latest"|];
54+
let latestVersionLabel = "v0.9";
55+
let version = "latest";
56+
57+
<CategoryDocsLayout
58+
theme=`Reason
59+
components
60+
metaTitleCategory="React"
61+
availableVersions
62+
latestVersionLabel
63+
version
64+
title
65+
breadcrumbs
66+
?frontmatter>
67+
children
68+
</CategoryDocsLayout>;
69+
};

re_pages/DocsOverview.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ let default = (~showVersionSelect=true) => {
4242

4343
let ecosystem = [|
4444
("GenType", "/docs/gentype/latest/introduction"),
45-
("ReasonReact", "https://reasonml.github.io/reason-react"),
45+
("ReasonReact (official)", "https://reasonml.github.io/reason-react"),
46+
("ReasonReact (new docs WIP)", "/docs/react/latest/introduction"),
4647
("Reanalyze", "https://github.com/reason-association/reanalyze"),
4748
|];
4849

@@ -76,7 +77,6 @@ let default = (~showVersionSelect=true) => {
7677
};
7778

7879
<>
79-
<Meta title="Overview | ReScript Documentation" />
8080
<div>
8181
versionSelect
8282
<div className="mb-6" />

scripts/extract-tocs.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,37 @@ const createV800ManualToc = () => {
143143
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
144144
};
145145

146+
147+
const createReactToc = () => {
148+
const MD_DIR = path.join(__dirname, "../pages/docs/react/latest");
149+
const TARGET_FILE = path.join(__dirname, "../index_data/react_latest_toc.json");
150+
151+
const FILE_ORDER = [
152+
"introduction",
153+
"installation",
154+
"elements-and-jsx",
155+
"rendering-elements",
156+
"components-and-props",
157+
"arrays-and-keys",
158+
"refs-and-the-dom",
159+
"hooks-overview",
160+
"hooks-state",
161+
"hooks-reducer",
162+
"hooks-effect",
163+
"hooks-context",
164+
"hooks-ref",
165+
"hooks-custom",
166+
];
167+
168+
const files = glob.sync(`${MD_DIR}/*.md?(x)`);
169+
const ordered = orderFiles(files, FILE_ORDER);
170+
171+
const result = ordered.map(processFile);
172+
const toc = createTOC(result);
173+
174+
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
175+
};
176+
146177
const createGenTypeToc = () => {
147178
const MD_DIR = path.join(__dirname, "../pages/docs/gentype/latest");
148179
const TARGET_FILE = path.join(__dirname, "../index_data/gentype_toc.json");
@@ -184,5 +215,6 @@ debugToc();
184215
createLatestManualToc();
185216
createV800ManualToc();
186217
createReasonCompilerToc();
218+
createReactToc();
187219
createGenTypeToc();
188220
createCommunityToc();

0 commit comments

Comments
 (0)