Skip to content

Commit 96d9032

Browse files
committed
more mdx work
1 parent 8c812c6 commit 96d9032

File tree

8 files changed

+54
-16
lines changed

8 files changed

+54
-16
lines changed

app/root.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ let default = () => {
3232
<html>
3333
<head>
3434
<Links />
35+
<Meta />
3536
<link rel="icon" href="data:image/x-icon;base64,AA" />
3637
</head>
3738
<body>

app/routes/MdxRoute.res

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ let manualTableOfContents = () => {
100100
categories
101101
}
102102

103+
let reactTableOfContents = () => {
104+
let groups =
105+
allMdx
106+
->filterMdxPages("docs/react")
107+
->groupBySection
108+
->Dict.mapValues(values => values->sortSection->convertToNavItems)
109+
110+
// Console.log(groups)
111+
112+
// these are the categories that appear in the sidebar
113+
let categories: array<SidebarLayout.Sidebar.Category.t> = [
114+
{name: "Overview", items: groups->Dict.getUnsafe("Overview")},
115+
]
116+
117+
Console.log(categories)
118+
119+
categories
120+
}
121+
103122
let apiTableOfContents = () => {
104123
let groups =
105124
allMdx
@@ -139,10 +158,13 @@ let loader: Loader.t<loaderData> = async ({request}) => {
139158
let categories = {
140159
if pathname->String.includes("docs/manual/api") {
141160
Console.log(apiTableOfContents())
142-
[]
161+
apiTableOfContents()
143162
} else if pathname->String.includes("docs/manual") {
144163
manualTableOfContents()
164+
} else if pathname->String.includes("docs/react") {
165+
reactTableOfContents()
145166
} else {
167+
// TODO RR7 add react docs
146168
[]
147169
}
148170
}
@@ -194,18 +216,21 @@ let default = () => {
194216
(pathname :> string)->String.includes("docs/manual")
195217
? "ReScript Language Manual"
196218
: "Some other page"
197-
198-
if (
199-
(pathname :> string)->String.includes("docs/manual") ||
200-
(pathname :> string)->String.includes("docs/react")
201-
) {
202-
<DocsLayout metaTitleCategory categories activeToc={title: "Introduction", entries}>
203-
<div className="markdown-body"> {component()} </div>
204-
</DocsLayout>
205-
} else {
206-
// TODO Handle blog pages
207-
React.null
208-
}
219+
<>
220+
<title> {React.string(attributes.metaTitle->Option.getOr(attributes.title))} </title>
221+
<meta name="description" content={attributes.description->Option.getOr("")} />
222+
{if (
223+
(pathname :> string)->String.includes("docs/manual") ||
224+
(pathname :> string)->String.includes("docs/react")
225+
) {
226+
<DocsLayout metaTitleCategory categories activeToc={title: "Introduction", entries}>
227+
<div className="markdown-body"> {component()} </div>
228+
</DocsLayout>
229+
} else {
230+
// TODO Handle blog pages
231+
React.null
232+
}}
233+
</>
209234

210235
// </ManualDocsLayout.V1200Layout>
211236
}

app/routes/SyntaxLookupRoute.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
let default = () => {
2+
// TODO: RR7 implement syntax lookup page
23
<div> {React.string("This is the Syntax Lookup Route")} </div>
34
}

docs/react/introduction.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Introduction
33
description: "Introduction to ReScript & ReactJS"
44
canonical: "/docs/react/latest/introduction"
5+
section: "Overview"
56
---
67

78
# ReScript & React

src/SyntaxLookup.res

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ module Tag = {
105105
py-1 px-3 rounded text-16
106106
${deprecated
107107
? "hover:bg-gray-30 bg-gray-50 text-gray-80 line-through"
108-
: "hover:bg-fire hover:text-white bg-fire-5 text-fire"}`}>
108+
: "hover:bg-fire hover:text-white bg-fire-5 text-fire"}`}
109+
>
109110
{React.string(text)}
110111
</span>
111112
}
@@ -176,7 +177,7 @@ let decode = (json: JSON.t) => {
176177
}
177178
}
178179

179-
let default = (props: props) => {
180+
let make = (props: props) => {
180181
let {mdxSources} = props
181182

182183
let allItems = mdxSources->Array.map(mdxSource => {

src/SyntaxLookup.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type props
22
type params
33

4-
let default: props => React.element
4+
// TODO RR7 pass the props correctly
5+
let make: props => React.element
56
let getStaticProps: Next.GetStaticProps.t<props, params>

src/bindings/ReactRouter.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ module Outlet = {
2626
external make: unit => React.element = "Outlet"
2727
}
2828

29+
module Meta = {
30+
@module("react-router") @react.component
31+
external make: unit => React.element = "Meta"
32+
}
33+
2934
module Links = {
3035
@module("react-router") @react.component
3136
external make: unit => React.element = "Links"
@@ -94,6 +99,7 @@ module Mdx = {
9499
canonical: Path.t,
95100
category?: string,
96101
description?: string,
102+
metaTitle?: string,
97103
order?: int,
98104
path: string,
99105
section?: string,

src/layouts/SidebarLayout.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ let make = (
273273
| Some(categories) =>
274274
let items = categories->Array.flatMap(c => c.items)
275275

276+
Console.log(items)
277+
276278
switch items->Array.findIndex(item => item.href === location.pathname) {
277279
| -1 => React.null
278280
| i =>

0 commit comments

Comments
 (0)