-
-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathBlog.res
More file actions
281 lines (261 loc) · 8.66 KB
/
Blog.res
File metadata and controls
281 lines (261 loc) · 8.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
module Link = ReactRouter.Link
let defaultPreviewImg = "/Art-3-rescript-launch.avif"
// For encoding reasons, see https://shripadk.github.io/react/docs/jsx-gotchas.html
let middleDotSpacer = " " ++ (String.fromCharCode(183) ++ " ")
module Badge = {
@react.component
let make = (~badge: BlogFrontmatter.Badge.t) => {
let bgColor = switch badge {
| Preview | Roadmap | Release | Community => "bg-turtle"
| Testing => "bg-orange"
}
let text = badge->BlogFrontmatter.Badge.toString
<div
className={bgColor ++ " flex items-center h-6 font-medium tracking-tight text-gray-80-tr text-14 px-2 rounded-sm"}
>
<div>
<img className="h-3 block mr-1" src="/star.svg" />
</div>
<div> {React.string(text)} </div>
</div>
}
}
type category =
/** Actually only unarchived */
| All
| Archived
module CategorySelector = {
@react.component
let make = (~selected: category) => {
let tabs = [All, Archived]
<div className="text-16 w-full flex items-center justify-between text-gray-60">
{tabs
->Array.map(tab => {
// Deep comparison here!
let isActive = selected == tab
let text = (tab :> string)
let href = switch tab {
| All => "/blog"
| Archived => "/blog/archived"
}
let className =
switch isActive {
| true => "bg-gray-20 text-gray-80 rounded py-1"
| false => "hover:cursor-pointer bg-white hover:text-gray-80"
} ++ " px-4 inline-block"
<Link.String key=text to=href className> {React.string(text)} </Link.String>
})
->React.array}
</div>
}
}
module BlogCard = {
@react.component
let make = (
~previewImg: option<string>=?,
~title: string="Unknown Title",
~author as _: BlogFrontmatter.author,
~category: option<string>=?,
~badge: option<BlogFrontmatter.Badge.t>=?,
~date: Date.t,
~slug: string,
) =>
<section className="h-full">
<div className="relative">
<ReactRouter.Link to=#"/syntax-lookup" />
{switch badge {
| None => React.null
| Some(badge) =>
<div className="absolute z-10 bottom-0 mb-4 -ml-2">
<Badge badge />
</div>
}}
<Link.String to={`/blog/${slug}`} className="relative hl-title block mb-4 pt-9/16">
{
let className = "absolute top-0 h-full w-full object-cover"
switch previewImg {
| Some(src) => <img className src loading={#lazy} />
| None => <img className src=defaultPreviewImg loading={#lazy} />
}
}
</Link.String>
</div>
<div className="px-2">
<Link.String to={`/blog/${slug}`}>
<h2 className="hl-4"> {React.string(title)} </h2>
</Link.String>
<div className="captions text-gray-40 pt-1">
{switch category {
| Some(category) =>
<>
{React.string(category)}
{React.string(` · `)}
</>
| None => React.null
}}
{React.string(date->Util.Date.toDayMonthYear)}
</div>
</div>
</section>
}
module FeatureCard = {
@react.component
let make = (
~previewImg: option<string>=?,
~title: string="Unknown Title",
~author: BlogFrontmatter.author,
~badge: option<BlogFrontmatter.Badge.t>=?,
~date: Date.t,
~category: option<string>=?,
~firstParagraph: string="",
~slug: string,
) => {
let authorImg = switch author.imgUrl {
| "" => React.null
| imgUrl =>
<div className="inline-block w-4 h-4 mr-2">
<img className="h-full w-full rounded-full" src=imgUrl />
</div>
}
<section
className="flex sm:px-4 md:px-8 lg:px-0 flex-col justify-end lg:flex-row sm:items-center h-full"
>
<div className="w-full h-full sm:self-start md:self-auto max-h-101.75">
<Link.String to={`/blog/${slug}`} className="relative block pt-2/3">
{switch badge {
| Some(badge) =>
<div className="absolute z-10 top-0 mt-10 ml-4 lg:-ml-4">
<Badge badge />
</div>
| None => React.null
}}
{
let className = "absolute top-0 h-full w-full object-cover"
switch previewImg {
| Some(src) => <img className src />
| None => <img className src=defaultPreviewImg loading={#eager} />
}
}
</Link.String>
</div>
<div
className="relative px-4 lg:self-auto sm:pt-12 md:px-20 sm:self-start md:-mt-20 mt-4 bg-white lg:w-full lg:pt-0 lg:mt-0 lg:px-0 lg:ml-12"
>
<div className="max-w-400 ">
<h2 className="hl-1"> {React.string(title)} </h2>
<div className="mb-6">
<div className="flex items-center body-sm text-gray-40 mt-2 mb-5">
authorImg
<div>
<a
className="hover:text-gray-60"
href={switch author.social {
| X(handle) => "https://x.com/" ++ handle
| Bluesky(handle) => "https://bsky.app/profile/" ++ handle
}}
rel="noopener noreferrer"
>
{React.string(author.fullname)}
</a>
{switch category {
| Some(category) =>
<>
{React.string(middleDotSpacer)}
{React.string(category)}
{React.string(middleDotSpacer)}
</>
| None => React.string(middleDotSpacer)
}}
{date->Util.Date.toDayMonthYear->React.string}
</div>
</div>
<p className="body-md text-gray-70"> {React.string(firstParagraph)} </p>
</div>
</div>
<Link.String to={`/blog/${slug}`}>
<Button> {React.string("Read Article")} </Button>
</Link.String>
</div>
</section>
}
}
type params = {slug: string}
@react.component
let make = (~posts: array<BlogApi.post>, ~category: category): React.element => {
let content = if Array.length(posts) === 0 {
<div className="mt-8">
<Markdown.H1> {React.string("Blog not yet available")} </Markdown.H1>
<Markdown.Warn> {React.string("This blog is currently in the works.")} </Markdown.Warn>
</div>
} else {
let result = switch Array.length(posts) {
| 0 => <div> {React.string("No posts for this category available...")} </div>
| _ =>
let first = Array.getUnsafe(posts, 0)
let rest = Array.slice(posts, ~start=1)
let featureBox =
<div className="w-full mb-24 lg:px-8 xl:px-0">
<FeatureCard
previewImg=?{first.frontmatter.previewImg->Nullable.toOption}
title=first.frontmatter.title
badge=?{first.frontmatter.badge->Nullable.toOption}
author=first.frontmatter.author
firstParagraph=?{first.frontmatter.description->Nullable.toOption}
date={first.frontmatter.date->DateStr.toDate}
slug={BlogApi.blogPathToSlug(first.path)}
/>
</div>
let postsBox = switch rest {
| [] => React.null
| rest =>
<div
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"
>
{Array.map(rest, post => {
let badge = post.frontmatter.badge->Nullable.toOption
<BlogCard
key={post.path}
previewImg=?{post.frontmatter.previewImg->Nullable.toOption}
title=post.frontmatter.title
author=post.frontmatter.author
?badge
date={post.frontmatter.date->DateStr.toDate}
slug={BlogApi.blogPathToSlug(post.path)}
/>
})->React.array}
</div>
}
<>
featureBox
postsBox
</>
}
<>
<div className="hidden sm:flex justify-center ">
<div className="my-16 w-full max-w-48">
<CategorySelector selected=category />
</div>
</div>
result
</>
}
<>
<div className="text-gray-80 text-18">
<div className="flex justify-center overflow-hidden">
<main className="min-w-320 lg:align-center w-full lg:px-0 max-w-1280 pb-48">
<div className="flex justify-center">
<div className="w-full max-w-266.5"> content </div>
</div>
</main>
</div>
<Footer />
</div>
</>
}
// let getStaticProps_Archived: Next.GetStaticProps.t<props, params> = async _ctx => {
// let props = {
// posts: BlogApi.getArchivedPosts(),
// category: Archived,
// }
// {"props": props}
// }