Skip to content

Commit 0a505e7

Browse files
committed
static builds are working
1 parent 58001ca commit 0a505e7

File tree

15 files changed

+169
-130
lines changed

15 files changed

+169
-130
lines changed

app/routes/ApiRoute.resi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type loaderData = ApiDocs.props
2+
3+
type rec apiItem = {
4+
id: string,
5+
kind: string,
6+
name: string,
7+
items?: array<apiItem>,
8+
docStrings: array<string>,
9+
}
10+
11+
let loader: ReactRouter.Loader.t<loaderData>
12+
13+
let default: unit => React.element

app/routes/BlogRoute.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ type loaderData = {posts: array<BlogApi.post>, category: Blog.category}
22

33
let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
44
let showArchived = request.url->String.includes("archived")
5-
let posts: array<BlogApi.post> = MdxRoute.posts()->Array.filter(post => {
5+
let posts = async () =>
6+
(await Mdx.allMdx())->Mdx.filterMdxPages("blog")->Array.map(BlogLoader.transform)
7+
8+
let posts: array<BlogApi.post> = (await posts())->Array.filter(post => {
69
post.archived == showArchived
710
})
811
let data = {posts, category: All}

app/routes/BlogRoute.resi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type loaderData = {posts: array<BlogApi.post>, category: Blog.category}
2+
3+
let loader: ReactRouter.Loader.t<loaderData>
4+
5+
@react.component
6+
let default: unit => React.element

app/routes/MdxRoute.res

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ let components = {
4646

4747
let convertToNavItems = (items, rootPath) =>
4848
Array.map(items, (item): SidebarLayout.Sidebar.NavItem.t => {
49+
let href = switch item.slug {
50+
| Some(slug) => `${rootPath}/${slug}`
51+
| None => rootPath
52+
}
4953
{
5054
name: item.title,
51-
href: `${rootPath}/${item.slug}`,
55+
href,
5256
}
5357
})
5458

@@ -64,14 +68,14 @@ let getGroup = (groups, groupName): SidebarLayout.Sidebar.Category.t => {
6468
let getAllGroups = (groups, groupNames): array<SidebarLayout.Sidebar.Category.t> =>
6569
groupNames->Array.map(item => getGroup(groups, item))
6670

67-
let blogPosts = () => {
68-
allMdx->filterMdxPages("blog")
71+
let blogPosts = async () => {
72+
(await allMdx())->filterMdxPages("blog")
6973
}
7074

7175
// These are the pages for the language manual, sorted by their "order" field in the frontmatter
72-
let manualTableOfContents = () => {
76+
let manualTableOfContents = async () => {
7377
let groups =
74-
allMdx
78+
(await allMdx())
7579
->filterMdxPages("docs/manual")
7680
->groupBySection
7781
->Dict.mapValues(values => values->sortSection->convertToNavItems("/docs/manual"))
@@ -92,9 +96,9 @@ let manualTableOfContents = () => {
9296
categories
9397
}
9498

95-
let reactTableOfContents = () => {
99+
let reactTableOfContents = async () => {
96100
let groups =
97-
allMdx
101+
(await allMdx())
98102
->filterMdxPages("docs/react")
99103
->groupBySection
100104
->Dict.mapValues(values => values->sortSection->convertToNavItems("/docs/react"))
@@ -108,8 +112,6 @@ let reactTableOfContents = () => {
108112
categories
109113
}
110114

111-
let posts = () => allMdx->filterMdxPages("blog")->Array.map(BlogLoader.transform)
112-
113115
let loader: Loader.t<loaderData> = async ({request}) => {
114116
let {pathname} = WebAPI.URL.make(~url=request.url)
115117

@@ -133,17 +135,17 @@ let loader: Loader.t<loaderData> = async ({request}) => {
133135
if pathname == "/docs/manual/api" {
134136
[]
135137
} else if pathname->String.includes("docs/manual") {
136-
manualTableOfContents()
138+
await manualTableOfContents()
137139
} else if pathname->String.includes("docs/react") {
138-
reactTableOfContents()
140+
await reactTableOfContents()
139141
} else {
140142
[]
141143
}
142144
}
143145

144146
// TODO: this can be optionally called if we need markdown
145147
// TODO: extract this out into a separate function
146-
let fileContents = await allMdx
148+
let fileContents = await (await allMdx())
147149
->Array.filter(mdx => (mdx.path :> string)->String.includes(pathname))
148150
->Array.get(0)
149151
->Option.map(mdx => mdx.path)
@@ -205,10 +207,9 @@ let default = () => {
205207
</DocsLayout>
206208
} else {
207209
switch loaderData.blogPost {
208-
| Some({frontmatter, archived, path}) => {
209-
Console.log(frontmatter)
210-
<BlogArticle frontmatter isArchived=archived path> {component()} </BlogArticle>
211-
}
210+
| Some({frontmatter, archived, path}) => <BlogArticle frontmatter isArchived=archived path>
211+
{component()}
212+
</BlogArticle>
212213
| None => React.null // TODO: RR7 show an error
213214
}
214215
}}

app/routes/MdxRoute.resi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type loaderData = {
2+
...Mdx.t,
3+
categories: array<SidebarLayout.Sidebar.Category.t>,
4+
entries: array<TableOfContents.entry>,
5+
blogPost?: BlogApi.post,
6+
}
7+
8+
let loader: ReactRouter.Loader.t<loaderData>
9+
10+
let default: unit => React.element

app/routes/SyntaxLookupRoute.res

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ open Mdx
33

44
type loaderData = {mdxSources: array<SyntaxLookup.item>}
55

6-
let convert = (mdx: Mdx.attributes): SyntaxLookup.item => {
7-
{
8-
category: SyntaxLookup.Category.fromString(mdx.category->Option.getOrThrow),
9-
id: mdx.id->Option.getOrThrow,
10-
keywords: mdx.keywords->Option.getOr([]),
11-
name: mdx.name->Option.getOrThrow,
12-
children: <div> {React.string("TODO: render MDX here")} </div>,
13-
status: SyntaxLookup.Status.fromString(mdx.status->Option.getOr("active")),
14-
summary: mdx.summary->Option.getOrThrow,
15-
}
16-
}
17-
186
let loader: Loader.t<loaderData> = async ({request}) => {
7+
let convert = (mdx: Mdx.attributes): SyntaxLookup.item => {
8+
{
9+
category: SyntaxLookup.Category.fromString(mdx.category->Option.getOrThrow),
10+
id: mdx.id->Option.getOrThrow,
11+
keywords: mdx.keywords->Option.getOr([]),
12+
name: mdx.name->Option.getOrThrow,
13+
children: <div> {React.string("TODO: render MDX here")} </div>,
14+
status: SyntaxLookup.Status.fromString(mdx.status->Option.getOr("active")),
15+
summary: mdx.summary->Option.getOrThrow,
16+
}
17+
}
1918
let allMdx = await Shims.runWithoutLogging(() => loadAllMdx())
2019

2120
let mdxSources =

app/routes/SyntaxLookupRoute.resi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type loaderData = {mdxSources: array<SyntaxLookup.item>}
2+
let loader: ReactRouter.Loader.t<loaderData>
3+
let default: unit => React.element

src/BlogArticle.res

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ module BlogHeader = {
5555

5656
let authors = Array.concat([author], co_authors)
5757

58-
Console.log2("authors", authors)
59-
6058
<div className="flex flex-col items-center">
6159
<div className="w-full max-w-740">
6260
<div className="text-gray-60 body-sm mb-5">

src/BlogLoader.res

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
let transform = (mdx: Mdx.attributes): BlogApi.post => {
22
// Archived posts are those in the archived folder
3-
let archived = mdx.path->String.includes("/archived")
3+
let archived = switch mdx.slug {
4+
// The path isn't included in the mdx attributes when we are rending a post vs listing them
5+
| Some(slug) => slug->String.includes("/archived/")
6+
| None => false
7+
}
48
{
5-
path: mdx.slug,
9+
// The path isn't included in the mdx attributes when we are rending a post vs listing them
10+
path: mdx.slug->Option.getOr("/blog"),
611
archived,
712
frontmatter: {
813
author: BlogFrontmatter.authors

src/Mdx.res

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type attributes = {
3636
section?: string,
3737
summary?: string,
3838
status?: string,
39-
slug: string,
39+
slug?: string,
4040
title: string,
4141
}
4242

@@ -69,7 +69,7 @@ external gfm: remarkPlugin = "default"
6969

7070
// The loadAllMdx function logs out all of the file contents as it reads them, which is noisy and not useful.
7171
// We can suppress that logging with this helper function.
72-
let allMdx = await Shims.runWithoutLogging(() => loadAllMdx())
72+
let allMdx = async () => await Shims.runWithoutLogging(() => loadAllMdx())
7373

7474
let sortSection = mdxPages =>
7575
Array.toSorted(mdxPages, (a: attributes, b: attributes) =>
@@ -93,77 +93,4 @@ let groupBySection = mdxPages =>
9393

9494
let filterMdxPages = (mdxPages, path) =>
9595
Array.filter(mdxPages, mdx => (mdx.path :> string)->String.includes(path))
96-
97-
/*
98-
Abstract type for representing mdx
99-
components mostly passed as children to
100-
the component context API
101-
*/
102-
/**
103-
* The code below is from Next's markdown, and I am not sure it is needed anymore.
104-
TODO: RR7
105-
*/
106-
type mdxComponent
107-
108-
external fromReactElement: React.element => mdxComponent = "%identity"
109-
110-
external arrToReactElement: array<mdxComponent> => React.element = "%identity"
111-
112-
let getMdxClassName: mdxComponent => option<string> = %raw("element => {
113-
if(element == null || element.props == null) {
114-
return;
115-
}
116-
return element.props.className;
117-
}")
118-
119-
let getMdxType: mdxComponent => string = %raw("element => {
120-
if(element == null || element.props == null) {
121-
return 'unknown';
122-
}
123-
return element.props.mdxType;
124-
}")
125-
126-
module MdxChildren = {
127-
type unknown
128-
129-
type t
130-
131-
type case =
132-
| String(string)
133-
| Element(mdxComponent)
134-
| Array(array<mdxComponent>)
135-
| Unknown(unknown)
136-
137-
let classify = (v: t): case =>
138-
if %raw(`function (a) { return a instanceof Array}`)(v) {
139-
Array((Obj.magic(v): array<mdxComponent>))
140-
} else if typeof(v) == #string {
141-
String((Obj.magic(v): string))
142-
} else if typeof(v) == #object {
143-
Element((Obj.magic(v): mdxComponent))
144-
} else {
145-
Unknown((Obj.magic(v): unknown))
146-
}
147-
148-
external toReactElement: t => React.element = "%identity"
149-
150-
// Sometimes an mdxComponent element can be a string
151-
// which means it doesn't have any children.
152-
// We will return the element as its own child then
153-
let getMdxChildren: mdxComponent => t = %raw("element => {
154-
if(typeof element === 'string') {
155-
return element;
156-
}
157-
if(element == null || element.props == null || element.props.children == null) {
158-
return;
159-
}
160-
return element.props.children;
161-
}")
162-
}
163-
164-
module Components = {
165-
// Used for reflection based logic in
166-
// components such as `code` or `ul`
167-
// with runtime reflection
168-
type unknown
169-
}
96+

0 commit comments

Comments
 (0)