Skip to content

Commit f21b9a1

Browse files
committed
Add scaffold for React doc pages & layout
1 parent e98d70b commit f21b9a1

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

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+
};

scripts/extract-tocs.js

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

182+
183+
const createReactToc = () => {
184+
const MD_DIR = path.join(__dirname, "../pages/docs/react/latest");
185+
const TARGET_FILE = path.join(__dirname, "../index_data/react_latest_toc.json");
186+
187+
const FILE_ORDER = [
188+
"introduction",
189+
"installation",
190+
"elements-and-jsx",
191+
"rendering-elements",
192+
"components-and-props",
193+
"arrays-and-keys",
194+
"refs-and-the-dom",
195+
"hooks-overview",
196+
"hooks-state",
197+
"hooks-reducer",
198+
"hooks-effect",
199+
"hooks-context",
200+
"hooks-ref",
201+
"hooks-custom",
202+
];
203+
204+
const files = glob.sync(`${MD_DIR}/*.md?(x)`);
205+
const ordered = orderFiles(files, FILE_ORDER);
206+
207+
const result = ordered.map(processFile);
208+
const toc = createTOC(result);
209+
210+
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
211+
};
212+
182213
const createGenTypeToc = () => {
183214
const MD_DIR = path.join(__dirname, "../pages/docs/gentype/latest");
184215
const SIDEBAR_JSON = path.join(__dirname, "../data/sidebar_gentype_latest.json");
@@ -238,5 +269,6 @@ debugToc();
238269
createLatestManualToc();
239270
createV800ManualToc();
240271
createReasonCompilerToc();
272+
createReactToc();
241273
createGenTypeToc();
242274
createCommunityToc();

0 commit comments

Comments
 (0)