Skip to content

Commit 6942b6b

Browse files
committed
working on blog listing page
1 parent 31058cb commit 6942b6b

File tree

7 files changed

+84
-41
lines changed

7 files changed

+84
-41
lines changed

app/routes/BlogRoute.res

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
type loaderData = {posts: array<BlogApi.post>, category: Blog.category}
2+
3+
let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
4+
let posts: array<BlogApi.post> = BlogLoader.posts()
5+
let data = {posts, category: All}
6+
data
7+
}
8+
19
@react.component
210
let default = () => {
3-
React.string("Blog Route Placeholder")
11+
let {posts, category} = ReactRouter.useLoaderData()
12+
<Blog posts category />
413
}

app/routes/MdxRoute.res

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ let getGroup = (groups, groupName): SidebarLayout.Sidebar.Category.t => {
9090
let getAllGroups = (groups, groupNames): array<SidebarLayout.Sidebar.Category.t> =>
9191
groupNames->Array.map(item => getGroup(groups, item))
9292

93+
let blogPosts = () => {
94+
allMdx->filterMdxPages("blog")
95+
}
96+
9397
// These are the pages for the language manual, sorted by their "order" field in the frontmatter
9498
let manualTableOfContents = () => {
9599
let groups =
@@ -137,6 +141,10 @@ let loader: Loader.t<loaderData> = async ({request}) => {
137141

138142
// TODO: actually render the blog pages
139143
if pathname->String.includes("blog") {
144+
let posts = blogPosts()
145+
146+
Console.log2("posts", posts)
147+
140148
let res: loaderData = {
141149
__raw: mdx.__raw,
142150
attributes: mdx.attributes,

app/routes/MdxRoute.resi

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Blog.res

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,8 @@ module FeatureCard = {
207207

208208
type params = {slug: string}
209209

210-
type props = {posts: array<BlogApi.post>, category: category}
211-
212-
let default = (props: props): React.element => {
213-
let {posts, category} = props
214-
210+
@react.component
211+
let make = (~posts: array<BlogApi.post>, ~category: category): React.element => {
215212
let content = if Array.length(posts) === 0 {
216213
/* <div> {React.string("Currently no posts available")} </div>; */
217214
<div className="mt-8">
@@ -301,20 +298,20 @@ let default = (props: props): React.element => {
301298
</>
302299
}
303300

304-
let getStaticProps_All: Next.GetStaticProps.t<props, params> = async _ctx => {
305-
let props = {
306-
posts: BlogApi.getLivePosts(),
307-
category: All,
308-
}
301+
// let getStaticProps_All: Next.GetStaticProps.t<props, params> = async _ctx => {
302+
// let props = {
303+
// posts: BlogApi.getLivePosts(),
304+
// category: All,
305+
// }
309306

310-
{"props": props}
311-
}
307+
// {"props": props}
308+
// }
312309

313-
let getStaticProps_Archived: Next.GetStaticProps.t<props, params> = async _ctx => {
314-
let props = {
315-
posts: BlogApi.getArchivedPosts(),
316-
category: Archived,
317-
}
310+
// let getStaticProps_Archived: Next.GetStaticProps.t<props, params> = async _ctx => {
311+
// let props = {
312+
// posts: BlogApi.getArchivedPosts(),
313+
// category: Archived,
314+
// }
318315

319-
{"props": props}
320-
}
316+
// {"props": props}
317+
// }

src/Blog.resi

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/BlogLoader.res

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
let transform = (mdx: ReactRouter.Mdx.attributes): BlogApi.post => {
2+
{
3+
path: mdx.path,
4+
archived: mdx.archived->Nullable.getOr(false),
5+
frontmatter: {
6+
author: BlogFrontmatter.authors
7+
->Array.find(author => author.username->String.includes(mdx.author))
8+
->Option.getOrThrow, // TODO: this is probably unsafe and needs to be fixed
9+
co_authors: (mdx.co_authors :> array<BlogFrontmatter.author>),
10+
date: mdx.date,
11+
previewImg: mdx.previewImg->Null.map(img => {
12+
Console.log2("img", img)
13+
img
14+
}),
15+
articleImg: mdx.articleImg,
16+
title: mdx.title,
17+
badge: mdx.badge
18+
->Nullable.map(badge => BlogFrontmatter.decodeBadge(badge))
19+
->Nullable.toOption
20+
->Null.fromOption,
21+
description: mdx.description->Null.fromOption,
22+
},
23+
}
24+
}
25+
26+
let posts = () => MdxRoute.allMdx->MdxRoute.filterMdxPages("blog")->Array.map(transform)

src/bindings/ReactRouter.res

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,31 @@ module Routes = {
108108
}
109109

110110
module Mdx = {
111+
type social = X(string) | Bluesky(string)
112+
113+
type author = {
114+
username: string,
115+
fullname: string,
116+
role: string,
117+
imgUrl: string,
118+
social: social,
119+
}
120+
121+
type badge =
122+
| Release
123+
| Testing
124+
| Preview
125+
| Roadmap
126+
| Community
127+
111128
type attributes = {
129+
archived: Nullable.t<bool>,
130+
author: string,
131+
co_authors: array<author>,
132+
date: DateStr.t,
133+
previewImg: Null.t<string>,
134+
articleImg: Null.t<string>,
135+
badge: Nullable.t<string>,
112136
canonical: Path.t,
113137
category?: string,
114138
description?: string,

0 commit comments

Comments
 (0)