ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Purge List.hd from Atom_client.ml

References: https://todo.sr.ht/~jonsterling/forester/190
References: https://todo.sr.ht/~jonsterling/forester/183

+16 -15
+16 -15
lib/frontend/Atom_client.ml
··· 42 42 43 43 open struct module A = Atom end 44 44 45 - let get_date_range (article : _ T.article) : (Human_datetime.t * Human_datetime.t) option = 46 - let dates = List.sort Human_datetime.compare article.frontmatter.dates in 47 - try 48 - Some (List.hd dates, List.hd (List.rev dates)) 49 - with 50 - | _ -> None 45 + let get_date_range (dates : Human_datetime.t list) : (Human_datetime.t * Human_datetime.t) option = 46 + let sorted = List.sort Human_datetime.compare dates in 47 + let@ first = Option.bind @@ List.nth_opt sorted 0 in 48 + let@ last = Option.bind @@ List.nth_opt (List.rev sorted) 0 in 49 + Some (first, last) 51 50 52 51 let render_title forest ?scope (frontmatter : _ T.frontmatter) = 53 52 A.title ··· 57 56 State.get_expanded_title ?scope frontmatter forest 58 57 59 58 let render_dates_exn dates = 60 - let sorted_dates = List.sort Human_datetime.compare dates in 61 - let oldest, newest = List.hd sorted_dates, List.hd (List.rev sorted_dates) in 62 - A.null 63 - [ 64 - A.published [] "%s" @@ Format.asprintf "%a" Human_datetime.pp_rfc_3399 oldest; 65 - A.updated [] "%s" @@ Format.asprintf "%a" Human_datetime.pp_rfc_3399 newest 66 - ] 59 + match get_date_range dates with 60 + | None -> A.null [] 61 + | Some (oldest, newest) -> 62 + A.null 63 + [ 64 + A.published [] "%s" @@ Format.asprintf "%a" Human_datetime.pp_rfc_3399 oldest; 65 + A.updated [] "%s" @@ Format.asprintf "%a" Human_datetime.pp_rfc_3399 newest 66 + ] 67 67 68 68 let render_updated_date dates = 69 69 let sorted_dates = List.sort Human_datetime.compare dates in 70 - let newest = List.hd (List.rev sorted_dates) in 71 - A.updated [] "%s" @@ Format.asprintf "%a" Human_datetime.pp newest 70 + match List.nth_opt (List.rev sorted_dates) 0 with 71 + | None -> A.null [] 72 + | Some newest -> A.updated [] "%s" @@ Format.asprintf "%a" Human_datetime.pp newest 72 73 73 74 let render_dates dates = 74 75 try render_dates_exn dates with _ -> A.null []