@@ -17,8 +17,8 @@ open Util.ReactStuff;
17
17
18
18
module Link = Next . Link ;
19
19
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" ;
22
22
23
23
// For encoding reasons, see https://shripadk.github.io/react/docs/jsx-gotchas.html
24
24
let middleDotSpacer = " " ++ Js . String . fromCharCode(183 ) ++ " " ;
@@ -53,6 +53,7 @@ module Badge = {
53
53
module CategorySelector = {
54
54
type selection =
55
55
| All
56
+ | Archived
56
57
| Category (BlogFrontmatter . Category . t );
57
58
58
59
let renderTab = (~text: string , ~isActive: bool , ~onClick) => {
@@ -76,7 +77,7 @@ module CategorySelector = {
76
77
~onSelected: selection => unit ,
77
78
) => {
78
79
let tabs =
79
- [| All |]
80
+ [| All , Archived |]
80
81
-> Js . Array2 . concat(Belt . Array . map(categories, cat => {Category (cat)}));
81
82
82
83
<div
@@ -95,6 +96,7 @@ module CategorySelector = {
95
96
let text =
96
97
switch (tab) {
97
98
| All => "All"
99
+ | Archived => "Archived"
98
100
| Category (cat ) => BlogFrontmatter . Category . toString(cat)
99
101
};
100
102
@@ -273,12 +275,13 @@ module Malformed = {
273
275
274
276
type props = {
275
277
posts: array (Post . t ),
278
+ archived: array (Post . t ),
276
279
malformed: array (Malformed . t ),
277
280
availableCategories: array (BlogFrontmatter . Category . t ),
278
281
};
279
282
280
283
let default = (props: props ): React . element => {
281
- let {availableCategories, posts, malformed} = props;
284
+ let {availableCategories, posts, malformed, archived } = props;
282
285
283
286
let (currentSelection , setSelection ) =
284
287
React . useState(() => CategorySelector . All );
@@ -327,6 +330,7 @@ let default = (props: props): React.element => {
327
330
let filtered =
328
331
switch (currentSelection) {
329
332
| All => posts
333
+ | Archived => archived
330
334
| Category (selected ) =>
331
335
Belt . Array . keep(posts, ({frontmatter}) => {
332
336
switch (Js . Null . toOption(frontmatter. category)) {
@@ -404,26 +408,20 @@ let default = (props: props): React.element => {
404
408
<> featureBox postsBox </>;
405
409
};
406
410
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
+ </>;
427
425
};
428
426
429
427
let overlayState = React . useState(() => false );
@@ -459,12 +457,12 @@ let default = (props: props): React.element => {
459
457
let getStaticProps : Next . GetStaticProps . t (props , params ) =
460
458
_ctx => {
461
459
let authors = BlogFrontmatter . Author . getAllAuthors() ;
462
- let (posts , malformed , availableCategories ) =
460
+ let (posts , malformed , archived , availableCategories ) =
463
461
BlogApi . getAllPosts()
464
462
-> Belt . Array . reduce(
465
- ([||] , [||] , [||] ),
463
+ ([||] , [||] , [||] , [||] ),
466
464
(acc, postData) => {
467
- let (posts , malformed , availableCategories ) = acc;
465
+ let (posts , malformed , archived , availableCategories ) = acc;
468
466
let id = postData. slug;
469
467
470
468
let decoded =
@@ -474,16 +472,13 @@ let getStaticProps: Next.GetStaticProps.t(props, params) =
474
472
| Error (message ) =>
475
473
let m = {Malformed . id, message};
476
474
let malformed = Belt . Array . concat(malformed, [| m|] );
477
- (posts, malformed, availableCategories);
475
+ (posts, malformed, archived , availableCategories);
478
476
| 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
+ };
487
482
488
483
let category = Js . Null . toOption(frontmatter. category);
489
484
@@ -495,25 +490,30 @@ let getStaticProps: Next.GetStaticProps.t(props, params) =
495
490
}
496
491
);
497
492
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)
500
494
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
+ };
509
509
};
510
510
511
- (posts, malformed, newAvailableCat);
511
+ (posts, malformed, archived , newAvailableCat);
512
512
};
513
513
},
514
514
);
515
515
516
- let props = {posts, malformed, availableCategories};
516
+ let props = {posts, malformed, archived , availableCategories};
517
517
518
518
Promise . resolved({"props" : props});
519
519
};
0 commit comments