Skip to content

Commit 1046aee

Browse files
committed
Adapt GenType & Community docs to new layout architecture
- Create sidebar files - Also adds missing frontmatters
1 parent bc38dac commit 1046aee

20 files changed

+148
-288
lines changed

data/sidebar_community.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Resources": [
3+
"overview",
4+
"code-of-conduct"
5+
]
6+
}

data/sidebar_gentype_latest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Overview": [
3+
"introduction",
4+
"getting-started",
5+
"usage"
6+
],
7+
"Advanced": [
8+
"supported-types"
9+
]
10+
}

next.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ const config = {
2828
}
2929
}
3030
return config
31-
}
31+
},
32+
async redirects() {
33+
return [
34+
{
35+
source: '/community',
36+
destination: '/community/overview',
37+
permanent: true,
38+
},
39+
]
40+
},
3241
};
3342

3443
module.exports = withMdx(withTM(withCSS(config)));

pages/community/code-of-conduct.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "Code of Conduct"
3+
description: "Our working codex for the ReScript community"
4+
canonical: "/community/code-of-conduct"
5+
---
6+
17
# Code of Conduct
28

39
## Our Pledge

pages/community.mdx renamed to pages/community/overview.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "Overview"
3+
description: "Community Resources Overview"
4+
canonical: "/community/overview"
5+
---
6+
17
# Community
28

39
## Core Team

pages/docs/gentype/latest/getting-started.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "Getting Started"
3+
description: "How to get started with genType in your ReScript projects"
4+
canonical: "/docs/gentype/latest/getting-started"
5+
---
6+
17
# Getting Started
28

39
`genType` is tightly integrated in the ReScript Compiler. It only requires minimal setup.

pages/docs/gentype/latest/introduction.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "Introduction"
3+
description: "GenType - Interoperability between ReScript and TypeScript / Flow"
4+
canonical: "/docs/gentype/latest/introduction"
5+
---
6+
17
# GenType
28

39
`genType` is a code generation tool that lets you export ReScript values and types to use in JavaScript, and import JavaScript values and types into ReScript.

pages/docs/gentype/latest/supported-types.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "Supported Types"
3+
description: "Supported types and value convertion in GenType"
4+
canonical: "/docs/gentype/latest/supported-types"
5+
---
6+
17
# Supported Types
28

39
<Intro>

scripts/extract-tocs.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,39 @@ const createV800ManualToc = () => {
181181

182182
const createGenTypeToc = () => {
183183
const MD_DIR = path.join(__dirname, "../pages/docs/gentype/latest");
184-
const TARGET_FILE = path.join(__dirname, "../index_data/gentype_toc.json");
184+
const SIDEBAR_JSON = path.join(__dirname, "../data/sidebar_gentype_latest.json");
185+
const TARGET_FILE = path.join(__dirname, "../index_data/gentype_latest_toc.json");
185186

186-
const files = glob.sync(`${MD_DIR}/*.md?(x)`);
187-
const result = files.map(processFile);
187+
const sidebarJson = JSON.parse(fs.readFileSync(SIDEBAR_JSON));
188+
189+
const FILE_ORDER = Object.values(sidebarJson).reduce((acc, items) => {
190+
return acc.concat(items)
191+
},[]);
192+
193+
const files = glob.sync(`${MD_DIR}/*.?(js|md?(x))`);
194+
const ordered = orderFiles(files, FILE_ORDER);
195+
196+
const result = ordered.map((filepath) => processFile(filepath, sidebarJson));
188197
const toc = createTOC(result);
189198

190199
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");
191200
};
192201

193202
const createCommunityToc = () => {
194203
const MD_DIR = path.join(__dirname, "../pages/community");
204+
const SIDEBAR_JSON = path.join(__dirname, "../data/sidebar_community.json");
195205
const TARGET_FILE = path.join(__dirname, "../index_data/community_toc.json");
196206

197-
const files = glob.sync(`${MD_DIR}/*.md?(x)`);
198-
const result = files.map(processFile);
207+
const sidebarJson = JSON.parse(fs.readFileSync(SIDEBAR_JSON));
208+
209+
const FILE_ORDER = Object.values(sidebarJson).reduce((acc, items) => {
210+
return acc.concat(items)
211+
},[]);
212+
213+
const files = glob.sync(`${MD_DIR}/*.?(js|md?(x))`);
214+
const ordered = orderFiles(files, FILE_ORDER);
215+
216+
const result = ordered.map((filepath) => processFile(filepath, sidebarJson));
199217
const toc = createTOC(result);
200218

201219
fs.writeFileSync(TARGET_FILE, JSON.stringify(toc), "utf8");

src/common/App.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/App.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// https://adamwathan.me/2019/10/17/persistent-layout-patterns-in-nextjs/
77

88
// Register all the highlightjs stuff for the whole application
9-
%%raw(
10-
`
9+
%%raw(`
1110
let hljs = require('highlight.js/lib/highlight');
1211
let js = require('highlight.js/lib/languages/javascript');
1312
let ocaml = require('highlight.js/lib/languages/ocaml');
@@ -29,8 +28,7 @@
2928
hljs.registerLanguage('text', text);
3029
hljs.registerLanguage('html', html);
3130
hljs.registerLanguage('diff', diff);
32-
`
33-
)
31+
`)
3432

3533
type pageComponent = React.component<{.}>
3634
type pageProps = {.}
@@ -96,11 +94,13 @@ let make = (props: props): React.element => {
9694
}
9795
| {base: ["docs", "reason-compiler"], version: Latest} =>
9896
<ReasonCompilerDocsLayout> content </ReasonCompilerDocsLayout>
99-
| {base: ["docs", "gentype"], version: Latest} => <GenTypeDocsLayout> content </GenTypeDocsLayout>
97+
| {base: ["docs", "gentype"], version: Latest} =>
98+
<GenTypeDocsLayout frontmatter={component->frontmatter}> content </GenTypeDocsLayout>
10099
// common routes
101100
| {base} =>
102101
switch Belt.List.fromArray(base) {
103-
| list{"community", ..._rest} => <CommunityLayout> content </CommunityLayout>
102+
| list{"community", ..._rest} =>
103+
<CommunityLayout frontmatter={component->frontmatter}> content </CommunityLayout>
104104
| list{"try"} => content
105105
| list{"blog"} => content // Blog implements its own layout as well
106106
| list{"packages"} => content

src/layouts/CommunityLayout.js

Lines changed: 18 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/layouts/CommunityLayout.res

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,16 @@
1-
// Structure defined by `scripts/extract-tocs.js`
2-
let tocData: Js.Dict.t<{
3-
"title": string,
4-
"headers": array<{
5-
"name": string,
6-
"href": string,
7-
}>,
8-
}> = %raw("require('index_data/community_toc.json')")
9-
10-
module NavItem = SidebarLayout.Sidebar.NavItem
11-
module Category = SidebarLayout.Sidebar.Category
12-
module Toc = SidebarLayout.Toc
13-
14-
let overviewNavs = [
15-
{
16-
open NavItem
17-
{name: "Overview", href: "/community"}
18-
},
19-
{name: "Code of Conduct", href: "/community/code-of-conduct"},
20-
/* {name: "Events & Meetups", href: "/community/events"}, */
21-
/* {name: "Articles & Videos", href: "/community/articles-and-videos"}, */
22-
/* {name: "Get involved", href: "/community/get-involved"}, */
23-
]
24-
25-
let categories = [
26-
{
27-
open Category
28-
{name: "Resources", items: overviewNavs}
29-
},
30-
]
1+
module CommunityLayout = DocsLayout.Make({
2+
// Structure defined by `scripts/extract-tocs.js`
3+
let tocData: SidebarLayout.Toc.raw = %raw("require('index_data/community_toc.json')")
4+
})
315

326
@react.component
33-
let make = (~components=Markdown.default, ~children) => {
34-
let router = Next.Router.useRouter()
35-
let route = router.route
36-
37-
let activeToc: option<Toc.t> = {
38-
open Belt.Option
39-
Js.Dict.get(tocData, route)->map(data => {
40-
let title = data["title"]
41-
let entries = Belt.Array.map(data["headers"], header => {
42-
Toc.header: header["name"],
43-
href: "#" ++ header["href"],
44-
})
45-
{Toc.title: title, entries: entries}
46-
})
47-
}
48-
49-
let url = Url.parse(route)
50-
51-
let breadcrumbs = if route === "/community" {
52-
open Url
53-
list{{name: "Community", href: "/community"}, {name: "Overview", href: ""}}
54-
} else {
55-
DocsLayout.makeBreadcrumbsFromPaths(~basePath="", url.base)
56-
}
7+
let make = (~frontmatter: option<Js.Json.t>=?, ~components=Markdown.default, ~children) => {
8+
let breadcrumbs = list{{Url.name: "Community", href: "/community"}}
579

5810
let title = "Community"
5911

60-
<DocsLayout
61-
theme=#Reason
62-
components
63-
metaTitleCategory="ReScript Documentation"
64-
categories
65-
title
66-
?activeToc
67-
breadcrumbs>
12+
<CommunityLayout
13+
theme=#Reason components metaTitleCategory="ReScript Community" title breadcrumbs ?frontmatter>
6814
children
69-
</DocsLayout>
15+
</CommunityLayout>
7016
}

src/layouts/CommunityLayout.resi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
@react.component
2-
let make: (~components: Mdx.Components.t=?, ~children: React.element) => React.element
2+
let make: (
3+
~frontmatter: Js.Json.t=?,
4+
~components: Mdx.Components.t=?,
5+
~children: React.element,
6+
) => React.element

0 commit comments

Comments
 (0)