Skip to content

Commit 7a704d4

Browse files
committed
Merge branch 'vlk/split-out-docs-react' of github.com:rescript-lang/rescript-lang.org into vlk/split-out-docs-guidelines
2 parents a88084e + 5bbdac3 commit 7a704d4

3 files changed

Lines changed: 28 additions & 40 deletions

File tree

app/routes.res

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ let docsGuidelinesRoutes =
4949
~alias="docs/guidelines",
5050
)->Array.map(path => route(path, "./routes/DocsGuidelinesRoute.jsx", ~options={id: path}))
5151

52-
let mdxRoutes = mdxRoutes("./routes/MdxRoute.jsx")->Array.filter(r => {
53-
let path = r.path->Option.getOr("")
54-
!(path->String.startsWith("blog")) &&
55-
!(path->String.startsWith("docs/manual")) &&
56-
!(path->String.startsWith("docs/react")) &&
57-
!(path->String.startsWith("docs/guidelines"))
58-
})
52+
let mdxRoutes = mdxRoutes("./routes/MdxRoute.jsx")->Array.filter(r =>
53+
!(
54+
r.path
55+
->Option.map(path =>
56+
path === "blog" ||
57+
String.startsWith(path, "blog/") ||
58+
path === "docs/manual" ||
59+
String.startsWith(path, "docs/manual/") ||
60+
path === "docs/react" ||
61+
String.startsWith(path, "docs/react/") ||
62+
path === "docs/guidelines" ||
63+
String.startsWith(path, "docs/guidelines/")
64+
)
65+
->Option.getOr(false)
66+
)
67+
)
5968

6069
let default = [
6170
index("./routes/LandingPageRoute.jsx"),

app/routes/MdxRoute.res

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,6 @@ let manualTableOfContents = async () => {
9999
categories
100100
}
101101

102-
let reactTableOfContents = async () => {
103-
let groups =
104-
(await allMdx(~filterByPaths=["markdown-pages/docs"]))
105-
->filterMdxPages("docs/react")
106-
->groupBySection
107-
->Dict.mapValues(values => values->sortSection->convertToNavItems("/docs/react"))
108-
109-
// these are the categories that appear in the sidebar
110-
let categories: array<SidebarLayout.Sidebar.Category.t> = getAllGroups(
111-
groups,
112-
["Overview", "Main Concepts", "Hooks & State Management", "Guides"],
113-
)
114-
115-
categories
116-
}
117-
118102
let communityTableOfContents = async () => {
119103
let groups =
120104
(await allMdx(~filterByPaths=["markdown-pages/community"]))
@@ -163,8 +147,6 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
163147
[]
164148
} else if pathname->String.includes("docs/manual") {
165149
await manualTableOfContents()
166-
} else if pathname->String.includes("docs/react") {
167-
await reactTableOfContents()
168150
} else if pathname->String.includes("community") {
169151
await communityTableOfContents()
170152
} else {
@@ -222,21 +204,11 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
222204
href: "/docs/manual/" ++ "introduction",
223205
},
224206
})
225-
: pathname->String.includes("docs/react")
226-
? Some(list{
227-
{Url.name: "Docs", href: "/docs/"},
228-
{
229-
Url.name: "rescript-react",
230-
href: "/docs/react/" ++ "introduction",
231-
},
232-
})
233207
: None
234208

235209
let metaTitleCategory = {
236210
let path = (pathname :> string)
237-
let title = if path->String.includes("docs/react") {
238-
"ReScript React"
239-
} else if path->String.includes("docs/manual/api") {
211+
let title = if path->String.includes("docs/manual/api") {
240212
"ReScript API"
241213
} else if path->String.includes("docs/manual") {
242214
"ReScript Language Manual"
@@ -322,7 +294,8 @@ let default = () => {
322294
</>
323295
} else if (
324296
(pathname :> string)->String.includes("docs/manual") ||
325-
(pathname :> string)->String.includes("docs/react")
297+
(pathname :> string)->String.includes("docs/react") ||
298+
(pathname :> string)->String.includes("docs/guidelines")
326299
) {
327300
<>
328301
<Meta title=title description={attributes.description->Nullable.getOr("")} />
@@ -333,8 +306,6 @@ let default = () => {
333306
if index === 0 {
334307
if (pathname :> string)->String.includes("docs/manual") {
335308
{...item, href: "/docs/manual/introduction"}
336-
} else if (pathname :> string)->String.includes("docs/react") {
337-
{...item, href: "/docs/react/introduction"}
338309
} else {
339310
item
340311
}

src/MdxFile.res

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ let resolveFilePath = (pathname, ~dir, ~alias) => {
3030
} else {
3131
pathname
3232
}
33-
let relativePath = path->String.replace(alias, dir)
33+
let relativePath = if path->String.startsWith(alias ++ "/") {
34+
let rest = path->String.slice(~start=String.length(alias) + 1, ~end=String.length(path))
35+
Node.Path.join2(dir, rest)
36+
} else if path->String.startsWith(alias) {
37+
let rest = path->String.slice(~start=String.length(alias), ~end=String.length(path))
38+
Node.Path.join2(dir, rest)
39+
} else {
40+
path
41+
}
3442
relativePath ++ ".mdx"
3543
}
3644

0 commit comments

Comments
 (0)