Skip to content

Commit 9797966

Browse files
committed
Remove reduce in Blog archived vs non-archived posts
1 parent e9e2fb2 commit 9797966

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

src/Blog.mjs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,11 @@ function $$default(props) {
283283
}
284284

285285
function getStaticProps(_ctx) {
286-
var match = Belt_Array.reduce(BlogApi.getAllPosts(undefined), [
287-
[],
288-
[]
289-
], (function (acc, postData) {
290-
var archived = acc[1];
291-
var posts = acc[0];
292-
if (postData.archived) {
293-
archived.push(postData);
294-
} else {
295-
posts.push(postData);
296-
}
297-
return [
298-
posts,
299-
archived
300-
];
286+
var match = Belt_Array.partition(BlogApi.getAllPosts(undefined), (function (data) {
287+
return data.archived;
301288
}));
302-
var props_posts = match[0];
303-
var props_archived = match[1];
289+
var props_posts = match[1];
290+
var props_archived = match[0];
304291
var props = {
305292
posts: props_posts,
306293
archived: props_archived

src/Blog.res

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ let default = (props: props): React.element => {
244244
author=first.frontmatter.author
245245
firstParagraph=?{first.frontmatter.description->Js.Null.toOption}
246246
date={first.frontmatter.date->DateStr.toDate}
247-
slug=BlogApi.blogPathToSlug(first.path)
247+
slug={BlogApi.blogPathToSlug(first.path)}
248248
/>
249249
</div>
250250

@@ -263,7 +263,7 @@ let default = (props: props): React.element => {
263263
author=post.frontmatter.author
264264
?badge
265265
date={post.frontmatter.date->DateStr.toDate}
266-
slug=BlogApi.blogPathToSlug(post.path)
266+
slug={BlogApi.blogPathToSlug(post.path)}
267267
/>
268268
})->React.array}
269269
</div>
@@ -312,21 +312,10 @@ let default = (props: props): React.element => {
312312
}
313313

314314
let getStaticProps: Next.GetStaticProps.t<props, params> = _ctx => {
315-
let (posts, archived) = BlogApi.getAllPosts()->Belt.Array.reduce(([], []), (
316-
acc,
317-
postData,
318-
) => {
319-
let (posts, archived) = acc
320-
if postData.archived {
321-
Js.Array2.push(archived, postData)->ignore
322-
} else {
323-
Js.Array2.push(posts, postData)->ignore
324-
}
325-
(posts, archived)
326-
})
315+
let (archived, nonArchived) = BlogApi.getAllPosts()->Belt.Array.partition(data => data.archived)
327316

328317
let props = {
329-
posts: posts,
318+
posts: nonArchived,
330319
archived: archived,
331320
}
332321

0 commit comments

Comments
 (0)