Skip to content

Commit e997c36

Browse files
committed
blog listing page is mostly working
1 parent 0321c41 commit e997c36

File tree

9 files changed

+56
-57
lines changed

9 files changed

+56
-57
lines changed

app/routes/MdxRoute.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ let default = () => {
214214
? "ReScript Language Manual"
215215
: "Some other page"
216216
<>
217-
<title> {React.string(attributes.metaTitle->Option.getOr(attributes.title))} </title>
218-
<meta name="description" content={attributes.description->Option.getOr("")} />
217+
<title> {React.string(attributes.metaTitle->Nullable.getOr(attributes.title))} </title>
218+
<meta name="description" content={attributes.description->Nullable.getOr("")} />
219219
{if (pathname :> string) == "/docs/manual/api" {
220220
<ApiOverviewLayout.Docs> {component()} </ApiOverviewLayout.Docs>
221221
} else if (

mdx-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"slug": "2022-08-25-release-10-0-0",
9898
"author": "rescript-team",
9999
"date": "2022-08-25",
100-
"previewImg": "static/blog/grid_0.jpeg",
100+
"previewImg": "/blog/grid_0.jpeg",
101101
"title": "ReScript 10.0",
102102
"badge": "release",
103103
"description": "The first community powered release.\n"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[ZoneTransfer]
2+
ZoneId=3
3+
ReferrerUrl=https://rescript-lang.org/blog
4+
HostUrl=https://rescript-lang.org/blog/grid_0.jpeg

src/Blog.res

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ module BlogCard = {
105105
</Link.String>
106106
</div>
107107
<div className="px-2">
108-
// <Link to=Url(`/blog/${slug}`)>
109-
// <h2 className="hl-4"> {React.string(title)} </h2>
110-
// </Link>
108+
<Link.String to={`/blog/${slug}`}>
109+
<h2 className="hl-4"> {React.string(title)} </h2>
110+
</Link.String>
111111
<div className="captions text-gray-40 pt-1">
112112
{switch category {
113113
| Some(category) =>
@@ -154,6 +154,7 @@ module FeatureCard = {
154154
</div>
155155
| None => React.null
156156
}}
157+
157158
{
158159
let className = "absolute top-0 h-full w-full object-cover"
159160
switch previewImg {
@@ -197,9 +198,9 @@ module FeatureCard = {
197198
<p className="body-md text-gray-70"> {React.string(firstParagraph)} </p>
198199
</div>
199200
</div>
200-
// <Link to=Url(`/blog/${slug}`)>
201-
// <Button> {React.string("Read Article")} </Button>
202-
// </Link>
201+
<Link.String to={`/blog/${slug}`}>
202+
<Button> {React.string("Read Article")} </Button>
203+
</Link.String>
203204
</div>
204205
</section>
205206
}
@@ -225,11 +226,11 @@ let make = (~posts: array<BlogApi.post>, ~category: category): React.element =>
225226
let featureBox =
226227
<div className="w-full mb-24 lg:px-8 xl:px-0">
227228
<FeatureCard
228-
previewImg=?{first.frontmatter.previewImg->Null.toOption}
229+
previewImg=?{first.frontmatter.previewImg->Nullable.toOption}
229230
title=first.frontmatter.title
230-
badge=?{first.frontmatter.badge->Null.toOption}
231+
badge=?{first.frontmatter.badge->Nullable.toOption}
231232
author=first.frontmatter.author
232-
firstParagraph=?{first.frontmatter.description->Null.toOption}
233+
firstParagraph=?{first.frontmatter.description->Nullable.toOption}
233234
date={first.frontmatter.date->DateStr.toDate}
234235
slug={BlogApi.blogPathToSlug(first.path)}
235236
/>
@@ -242,16 +243,17 @@ let make = (~posts: array<BlogApi.post>, ~category: category): React.element =>
242243
className="px-4 md:px-8 xl:px-0 grid grid-cols-1 xs:grid-cols-2 md:grid-cols-3 gap-20 gap-y-12 md:gap-y-24 w-full"
243244
>
244245
{Array.map(rest, post => {
245-
let badge = post.frontmatter.badge->Null.toOption
246+
let badge = post.frontmatter.badge->Nullable.toOption
246247

247248
<BlogCard
248249
key={post.path}
249-
previewImg=?{post.frontmatter.previewImg->Null.toOption}
250+
previewImg=?{post.frontmatter.previewImg->Nullable.toOption}
250251
title=post.frontmatter.title
251252
author=post.frontmatter.author
252253
?badge
253254
date={post.frontmatter.date->DateStr.toDate}
254-
slug={BlogApi.blogPathToSlug(post.path)}
255+
// TODO RR7 format blog urls
256+
slug={`/${encodeURI(post.frontmatter.title)}`}
255257
/>
256258
})->React.array}
257259
</div>
@@ -262,7 +264,6 @@ let make = (~posts: array<BlogApi.post>, ~category: category): React.element =>
262264
postsBox
263265
</>
264266
}
265-
266267
<>
267268
<div className="hidden sm:flex justify-center ">
268269
<div className="my-16 w-full max-w-48">
@@ -298,15 +299,6 @@ let make = (~posts: array<BlogApi.post>, ~category: category): React.element =>
298299
</>
299300
}
300301

301-
// let getStaticProps_All: Next.GetStaticProps.t<props, params> = async _ctx => {
302-
// let props = {
303-
// posts: BlogApi.getLivePosts(),
304-
// category: All,
305-
// }
306-
307-
// {"props": props}
308-
// }
309-
310302
// let getStaticProps_Archived: Next.GetStaticProps.t<props, params> = async _ctx => {
311303
// let props = {
312304
// posts: BlogApi.getArchivedPosts(),

src/BlogArticle.res

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module AuthorBox = {
4444
| Bluesky(handle) => "https://bsky.app/profile/" ++ handle
4545
}}
4646
className="hover:text-gray-80"
47-
rel="noopener noreferrer">
47+
rel="noopener noreferrer"
48+
>
4849
{React.string(author.fullname)}
4950
</a>
5051
<div className="text-gray-60"> {React.string(author.role)} </div>
@@ -148,17 +149,17 @@ let default = (props: props) => {
148149
<Meta
149150
siteName="ReScript Blog"
150151
title={title ++ " | ReScript Blog"}
151-
description=?{description->Null.toOption}
152-
ogImage={previewImg->Null.toOption->Option.getOr(Blog.defaultPreviewImg)}
152+
description=?{description->Nullable.toOption}
153+
ogImage={previewImg->Nullable.toOption->Option.getOr(Blog.defaultPreviewImg)}
153154
/>
154155
<div className="mb-10 md:mb-20">
155156
<BlogHeader
156157
date
157158
author
158159
co_authors
159160
title
160-
description={description->Null.toOption}
161-
articleImg={articleImg->Null.toOption}
161+
description={description->Nullable.toOption}
162+
articleImg={articleImg->Nullable.toOption}
162163
/>
163164
</div>
164165
<div className="flex justify-center">

src/BlogLoader.res

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
let transform = (mdx: ReactRouter.Mdx.attributes): BlogApi.post => {
2+
let archived = switch mdx.archived {
3+
| Nullable.Value(archived) => archived
4+
| _ => false
5+
}
6+
Console.log(mdx)
27
{
38
path: mdx.path,
4-
archived: mdx.archived->Nullable.getOr(false),
9+
archived,
510
frontmatter: {
611
author: BlogFrontmatter.authors
712
->Array.find(author => author.username->String.includes(mdx.author))
813
->Option.getOrThrow, // TODO: this is probably unsafe and needs to be fixed
914
co_authors: (mdx.co_authors :> array<BlogFrontmatter.author>),
1015
date: mdx.date,
11-
previewImg: mdx.previewImg->Null.map(img => {
12-
Console.log2("img", img)
13-
img
14-
}),
16+
previewImg: mdx.previewImg,
1517
articleImg: mdx.articleImg,
1618
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,
19+
badge: mdx.badge->Nullable.map(badge => BlogFrontmatter.decodeBadge(badge)),
20+
description: mdx.description,
21+
slug: `/blog${archived ? "/archived" : ""}/${mdx.slug}`,
2222
},
2323
}
2424
}

src/bindings/ReactRouter.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ module Mdx = {
132132
author: string,
133133
co_authors: array<author>,
134134
date: DateStr.t,
135-
previewImg: Null.t<string>,
136-
articleImg: Null.t<string>,
135+
previewImg: Nullable.t<string>,
136+
articleImg: Nullable.t<string>,
137137
badge: Nullable.t<string>,
138138
canonical: Path.t,
139139
category?: string,
140-
description?: string,
141140
id?: string,
142141
keywords?: array<string>,
143142
name?: string,
144-
metaTitle?: string,
143+
description: Nullable.t<string>,
144+
metaTitle: Nullable.t<string>,
145145
order?: int,
146146
path: string,
147147
section?: string,

src/common/BlogApi.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module RssFeed = {
149149
getAllPosts()
150150
->Array.map(post => {
151151
let fm = post.frontmatter
152-
let description = Null.toOption(fm.description)->Option.getOr("")
152+
let description = fm.description->Nullable.getOr("")
153153
{
154154
title: fm.title,
155155
href: baseUrl ++ "/blog/" ++ blogPathToSlug(post.path),

src/common/BlogFrontmatter.res

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ type t = {
9696
author: author,
9797
co_authors: array<author>,
9898
date: DateStr.t,
99-
previewImg: Null.t<string>,
100-
articleImg: Null.t<string>,
99+
previewImg: Nullable.t<string>,
100+
articleImg: Nullable.t<string>,
101101
title: string,
102-
badge: Null.t<Badge.t>,
103-
description: Null.t<string>,
102+
badge: Nullable.t<Badge.t>,
103+
description: Nullable.t<string>,
104+
slug: string,
104105
}
105106

106107
let decodeBadge = (str: string): Badge.t =>
@@ -147,20 +148,20 @@ let decode = (json: JSON.t): result<t, string> => {
147148
}
148149
let date = date->DateStr.fromString
149150
let badge = switch badge {
150-
| Some(String(badge)) => badge->decodeBadge->Null.Value
151-
| _ => Null
151+
| Some(String(badge)) => badge->decodeBadge->Nullable.Value
152+
| _ => Nullable.null
152153
}
153154
let previewImg = switch previewImg {
154-
| Some(String(previewImg)) => previewImg->Null.Value
155-
| _ => Null
155+
| Some(String(previewImg)) => previewImg->Nullable.Value
156+
| _ => Nullable.null
156157
}
157158
let articleImg = switch articleImg {
158-
| Some(String(articleImg)) => articleImg->Null.Value
159-
| _ => Null
159+
| Some(String(articleImg)) => articleImg->Nullable.Value
160+
| _ => Nullable.null
160161
}
161162
let description = switch description {
162-
| Some(String(description)) => description->Null.Value
163-
| _ => Null
163+
| Some(String(description)) => description->Nullable.Value
164+
| _ => Nullable.null
164165
}
165166
Ok({
166167
author,
@@ -171,6 +172,7 @@ let decode = (json: JSON.t): result<t, string> => {
171172
title,
172173
badge,
173174
description,
175+
slug: "/", // TODO RR7 - fix this to be the actual slug
174176
})
175177
| exception AuthorNotFound(str) => Error(str)
176178
| _ => Error(`Failed to decode: ${JSON.stringify(json)}`)

0 commit comments

Comments
 (0)