Skip to content

Commit

Permalink
Improve Events Directory (#2132)
Browse files Browse the repository at this point in the history
* remove past events

* utc datetime in events.ml

* add back OUPS Paris meetup Feb 29
  • Loading branch information
sabine committed Mar 5, 2024
1 parent 075252e commit 23b67ce
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 34 deletions.
4 changes: 3 additions & 1 deletion data/events/2024-02-09-oups.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ location:
long: 2.3522
url: https://www.meetup.com/ocaml-paris/events/299014082/
recurring_event_slug: ocaml-users-paris-oups
starts: "Feb 29, 2024 19:00 CET"
starts:
yyyy_mm_dd: "7024-02-29"
utc_hh_mm: "18:00"
---
6 changes: 4 additions & 2 deletions data/events/2024-04-22-mirageos-retreat.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ location:
long: -7.992047
url: https://retreat.mirage.io/
recurring_event_slug: mirageos-hack-retreat
starts: "April 22, 2024"
ends: "April 28, 2024"
starts:
yyyy_mm_dd: "2024-04-22"
ends:
yyyy_mm_dd: "2024-04-28"
---
6 changes: 4 additions & 2 deletions src/ocamlorg_data/data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,16 @@ module Event : sig
val get_by_slug : string -> t option
end

type utc_datetime = { yyyy_mm_dd : string; utc_hh_mm : string option }

type t = {
title : string;
url : string;
slug : string;
textual_location : string;
location : location option;
starts : string;
ends : string option;
starts : utc_datetime;
ends : utc_datetime option;
body_md : string;
body_html : string;
recurring_event : RecurringEvent.t option;
Expand Down
35 changes: 17 additions & 18 deletions src/ocamlorg_frontend/pages/community.eml
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
let render ~workshops ~recurring_events ~events =
let current_date =
let open Unix in
let tm = localtime (Unix.gettimeofday ()) in
Format.asprintf
"%04d-%02d-%02d"
(tm.tm_year + 1900)
(tm.tm_mon + 1)
tm.tm_mday
in
let old_workshops = List.filter (fun (w : Data.Workshop.t) -> w.date < current_date) workshops in
let upcoming_workshops = List.filter (fun (w : Data.Workshop.t) -> w.date >= current_date) workshops in
let upcoming_events = List.filter (fun (e : Data.Event.t) -> e.starts >= current_date) events in
let upcoming_events = Ocamlorg.Import.List.take 6 upcoming_events in
let render ~upcoming_workshops ~old_workshops ~recurring_events ~upcoming_events =
Community_layout.single_column_layout
~title:"The OCaml Community"
~description:"Looking to interact with people who are also interested in OCaml? Find out about upcoming events, read up on blogs from the community, sign up for OCaml mailing lists, and discover even more places to engage with people from the community!"
Expand Down Expand Up @@ -215,13 +202,25 @@ Community_layout.single_column_layout
<a href="<%s event.url %>" class="card dark:dark-card p-5 rounded-xl">
<p class="font-bold text-title dark:text-dark-title mb-2"><%s event.title %></p>
<div class="flex items-center space-x-2 mb-3">
<%s! Icons.map_pin "h-5 w-5 text-primary dark:text-dark-primary mr-2" %>
<p class="text-content dark:text-dark-content"><%s event.textual_location %></p>
<%s! Icons.map_pin "h-5 w-5 text-primary dark:text-dark-primary mr-2" %>
<p class="text-content dark:text-dark-content"><%s event.textual_location %></p>
</div>
<div class="flex items-center space-x-2 mt-2">
<%s! Icons.calendar "h-5 w-5 text-primary dark:text-dark-primary mr-2" %>
<p class="text-content dark:text-dark-content"><%s event.starts %></p>
<%s! Icons.calendar "h-5 w-5 text-primary dark:text-dark-primary mr-2" %>
<p class="text-content dark:text-dark-content">
<%s event.starts.yyyy_mm_dd %>
<%s Option.value ~default:"" event.starts.utc_hh_mm %>
</p>
</div>
<% match event.ends with | None -> () | Some ends -> ( %>
<div class="flex items-center space-x-2 mt-2">
<p class="ml-9 text-content dark:text-dark-content">
to
<%s ends.yyyy_mm_dd %>
<%s Option.value ~default:"" ends.utc_hh_mm %>
</p>
</div>
<% ) ;%>
</a>
<% ); %>
</div>
Expand Down
33 changes: 30 additions & 3 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,37 @@ let platform _req =
Dream.html (Ocamlorg_frontend.platform ~tutorials tools)

let community _req =
let workshops = Data.Workshop.all in
let recurring_events = Data.Event.RecurringEvent.all in
let events = Data.Event.all in
Dream.html (Ocamlorg_frontend.community ~workshops ~recurring_events ~events)
let current_date =
let open Unix in
let tm = localtime (Unix.gettimeofday ()) in
Format.asprintf "%04d-%02d-%02d" (tm.tm_year + 1900) (tm.tm_mon + 1)
tm.tm_mday
in
let old_workshops =
List.filter
(fun (w : Data.Workshop.t) -> w.date < current_date)
Data.Workshop.all
in
let upcoming_workshops =
List.filter
(fun (w : Data.Workshop.t) -> w.date >= current_date)
Data.Workshop.all
in
let upcoming_events =
List.filter
(fun (e : Data.Event.t) ->
e.starts.yyyy_mm_dd >= current_date
|| Option.is_some e.ends
&& e.ends
|> Option.map (fun (e : Data.Event.utc_datetime) -> e.yyyy_mm_dd)
|> Option.get >= current_date)
Data.Event.all
|> Ocamlorg.Import.List.take 6
in
Dream.html
(Ocamlorg_frontend.community ~old_workshops ~upcoming_workshops
~recurring_events ~upcoming_events)

let paginate ~req ~n items =
let items_per_page = n in
Expand Down
31 changes: 23 additions & 8 deletions tool/ood-gen/lib/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ module RecurringEvent = struct
let all () : t list = Utils.yaml_sequence_file decode "events/recurring.yml"
end

type utc_datetime = { yyyy_mm_dd : string; utc_hh_mm : string option }
[@@deriving of_yaml, show { with_path = false }]

type metadata = {
title : string;
url : string;
textual_location : string;
location : location option;
starts : string;
ends : string option;
starts : utc_datetime;
ends : utc_datetime option;
recurring_event_slug : string option;
}
[@@deriving of_yaml, show { with_path = false }]
Expand All @@ -44,8 +47,8 @@ type t = {
slug : string;
textual_location : string;
location : location option;
starts : string;
ends : string option;
starts : utc_datetime;
ends : utc_datetime option;
body_md : string;
body_html : string;
recurring_event : RecurringEvent.t option;
Expand Down Expand Up @@ -76,15 +79,22 @@ let decode (recurring_events : RecurringEvent.t list) (fpath, (head, body_md)) =
recurring_events)
metadata.recurring_event_slug
in

of_metadata ~body_md ~body_html ~recurring_event metadata)
metadata

let all () =
Utils.map_files (decode (RecurringEvent.all ())) "events/*.md"
|> List.sort (fun e1 e2 ->
(* Sort the events by reversed start date. *)
String.compare e2.starts e1.starts)
let t1 =
e1.starts.yyyy_mm_dd ^ " "
^ Option.value ~default:"00:00" e1.starts.utc_hh_mm
in
let t2 =
e2.starts.yyyy_mm_dd ^ " "
^ Option.value ~default:"00:00" e2.starts.utc_hh_mm
in
String.compare t2 t1)

let template () =
Format.asprintf
Expand All @@ -103,14 +113,19 @@ module RecurringEvent = struct
let all = %a
end

type utc_datetime = {
yyyy_mm_dd: string;
utc_hh_mm: string option;
}

type t =
{ title : string
; url : string
; slug : string
; textual_location : string
; location : location option
; starts : string
; ends : string option
; starts : utc_datetime
; ends : utc_datetime option
; body_md : string
; body_html : string
; recurring_event : RecurringEvent.t option
Expand Down

0 comments on commit 23b67ce

Please sign in to comment.