Skip to content

Commit 85c87c4

Browse files
committed
Add blog archive toggle
1 parent 30bcd3e commit 85c87c4

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

pages/blog.re

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ open Util.ReactStuff;
1717

1818
module Link = Next.Link;
1919

20-
let rescriptDefaultImg = "https://res.cloudinary.com/dmm9n7v9f/image/upload/v1598616442/reason%20association/rescript-lang.org/art-3-rescript-launch_ovoibg.jpg"
21-
let planetPreviewImg = "https://res.cloudinary.com/dmm9n7v9f/image/upload/v1587479463/Reason%20Association/reasonml.org/reasonml_art2_1280_vhzxnz.png"
20+
let rescriptDefaultImg = "https://res.cloudinary.com/dmm9n7v9f/image/upload/v1598616442/reason%20association/rescript-lang.org/art-3-rescript-launch_ovoibg.jpg";
21+
let planetPreviewImg = "https://res.cloudinary.com/dmm9n7v9f/image/upload/v1587479463/Reason%20Association/reasonml.org/reasonml_art2_1280_vhzxnz.png";
2222

2323
// For encoding reasons, see https://shripadk.github.io/react/docs/jsx-gotchas.html
2424
let middleDotSpacer = " " ++ Js.String.fromCharCode(183) ++ " ";
@@ -53,6 +53,7 @@ module Badge = {
5353
module CategorySelector = {
5454
type selection =
5555
| All
56+
| Archived
5657
| Category(BlogFrontmatter.Category.t);
5758

5859
let renderTab = (~text: string, ~isActive: bool, ~onClick) => {
@@ -76,7 +77,7 @@ module CategorySelector = {
7677
~onSelected: selection => unit,
7778
) => {
7879
let tabs =
79-
[|All|]
80+
[|All, Archived|]
8081
->Js.Array2.concat(Belt.Array.map(categories, cat => {Category(cat)}));
8182

8283
<div
@@ -95,6 +96,7 @@ module CategorySelector = {
9596
let text =
9697
switch (tab) {
9798
| All => "All"
99+
| Archived => "Archived"
98100
| Category(cat) => BlogFrontmatter.Category.toString(cat)
99101
};
100102

@@ -273,12 +275,13 @@ module Malformed = {
273275

274276
type props = {
275277
posts: array(Post.t),
278+
archived: array(Post.t),
276279
malformed: array(Malformed.t),
277280
availableCategories: array(BlogFrontmatter.Category.t),
278281
};
279282

280283
let default = (props: props): React.element => {
281-
let {availableCategories, posts, malformed} = props;
284+
let {availableCategories, posts, malformed, archived} = props;
282285

283286
let (currentSelection, setSelection) =
284287
React.useState(() => CategorySelector.All);
@@ -327,6 +330,7 @@ let default = (props: props): React.element => {
327330
let filtered =
328331
switch (currentSelection) {
329332
| All => posts
333+
| Archived => archived
330334
| Category(selected) =>
331335
Belt.Array.keep(posts, ({frontmatter}) => {
332336
switch (Js.Null.toOption(frontmatter.category)) {
@@ -404,26 +408,20 @@ let default = (props: props): React.element => {
404408
<> featureBox postsBox </>;
405409
};
406410

407-
let catSelector =
408-
// TODO: Reenable CategorySelector at some later point when it's useful
409-
if (false && Belt.Array.length(availableCategories) >= 2) {
410-
/* We hide the Category Selector for mobile for now*/
411-
<div className="hidden sm:flex justify-center ">
412-
<div
413-
className="my-16 w-full"
414-
style={Style.make(~maxWidth="32rem", ())}>
415-
<CategorySelector
416-
categories=availableCategories
417-
onSelected={selection => setSelection(_ => selection)}
418-
selected=currentSelection
419-
/>
420-
</div>
421-
</div>;
422-
} else {
423-
<div className="md:mt-32" />;
424-
};
425-
426-
<> catSelector result </>;
411+
<>
412+
<div className="hidden sm:flex justify-center ">
413+
<div
414+
className="my-16 w-full"
415+
style={Style.make(~maxWidth="12rem", ())}>
416+
<CategorySelector
417+
categories=availableCategories
418+
onSelected={selection => setSelection(_ => selection)}
419+
selected=currentSelection
420+
/>
421+
</div>
422+
</div>
423+
result
424+
</>;
427425
};
428426

429427
let overlayState = React.useState(() => false);
@@ -459,12 +457,12 @@ let default = (props: props): React.element => {
459457
let getStaticProps: Next.GetStaticProps.t(props, params) =
460458
_ctx => {
461459
let authors = BlogFrontmatter.Author.getAllAuthors();
462-
let (posts, malformed, availableCategories) =
460+
let (posts, malformed, archived, availableCategories) =
463461
BlogApi.getAllPosts()
464462
->Belt.Array.reduce(
465-
([||], [||], [||]),
463+
([||], [||], [||], [||]),
466464
(acc, postData) => {
467-
let (posts, malformed, availableCategories) = acc;
465+
let (posts, malformed, archived, availableCategories) = acc;
468466
let id = postData.slug;
469467

470468
let decoded =
@@ -474,16 +472,13 @@ let getStaticProps: Next.GetStaticProps.t(props, params) =
474472
| Error(message) =>
475473
let m = {Malformed.id, message};
476474
let malformed = Belt.Array.concat(malformed, [|m|]);
477-
(posts, malformed, availableCategories);
475+
(posts, malformed, archived, availableCategories);
478476
| Ok(frontmatter) =>
479-
// TODO: Right now we completely remove archived posts
480-
let posts =
481-
if (postData.archived) {
482-
posts;
483-
} else {
484-
let p = {Post.id, frontmatter};
485-
Belt.Array.concat(posts, [|p|]);
486-
};
477+
if (postData.archived) {
478+
Js.Array2.push(archived, {Post.id, frontmatter})->ignore;
479+
} else {
480+
Js.Array2.push(posts, {Post.id, frontmatter})->ignore;
481+
};
487482

488483
let category = Js.Null.toOption(frontmatter.category);
489484

@@ -495,25 +490,30 @@ let getStaticProps: Next.GetStaticProps.t(props, params) =
495490
}
496491
);
497492

498-
// We will only add categories that are not yet
499-
// accumulated from previous post frontmatters
493+
// TODO: For now we ignore categories alltogether (only show All | Archived)
500494
let newAvailableCat =
501-
switch (category) {
502-
| Some(category) =>
503-
if (hasCategory) {
504-
availableCategories;
505-
} else {
506-
Belt.Array.concat(availableCategories, [|category|]);
507-
}
508-
| None => availableCategories
495+
if (true || postData.archived) {
496+
availableCategories;
497+
} else {
498+
// We will only add categories that are not yet
499+
// accumulated from previous post frontmatters
500+
switch (category) {
501+
| Some(category) =>
502+
if (hasCategory) {
503+
availableCategories;
504+
} else {
505+
Belt.Array.concat(availableCategories, [|category|]);
506+
}
507+
| None => availableCategories
508+
};
509509
};
510510

511-
(posts, malformed, newAvailableCat);
511+
(posts, malformed, archived, newAvailableCat);
512512
};
513513
},
514514
);
515515

516-
let props = {posts, malformed, availableCategories};
516+
let props = {posts, malformed, archived, availableCategories};
517517

518518
Promise.resolved({"props": props});
519519
};

0 commit comments

Comments
 (0)