Skip to content

Commit

Permalink
feat: Add Events Feed (#2495)
Browse files Browse the repository at this point in the history
* feat: added dedupe logic

* feat: added event feed generating logic with new logic

* Apply suggestions from code review

* Update tool/ood-gen/lib/event.ml

* Formatting

* Apply suggestions from code review

* Apply suggestions from code review

* Update tool/ood-gen/lib/event.ml

* Update tool/ood-gen/lib/event.ml

Co-authored-by: Cuihtlauac Alvarado <cuihtlauac@users.noreply.github.com>

* prepare for merge

---------

Co-authored-by: Cuihtlauac Alvarado <cuihtlauac@users.noreply.github.com>
Co-authored-by: sabine <6594573+sabine@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 1, 2024
1 parent 23e8344 commit 818c78a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dune
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@
%{workspace_root}
(with-stdout-to
%{target}
(run %{gen_feed} video))))))
(run %{gen_feed} video)))))
(rule
(target events.xml)
(deps
(source_tree %{workspace_root}/data/events)
(:gen_feed %{workspace_root}/tool/ood-gen/bin/feed.exe))
(action
(chdir
%{workspace_root}
(with-stdout-to
%{target}
(run %{gen_feed} events))))))

(data_only_dirs playground data practice)
1 change: 1 addition & 0 deletions src/ocamlorg_static/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
%{workspace_root}/asset/planet.xml
%{workspace_root}/asset/changelog.xml
%{workspace_root}/asset/video.xml
%{workspace_root}/asset/events.xml
(source_tree %{workspace_root}/asset))
(action
(with-stdout-to
Expand Down
1 change: 1 addition & 0 deletions tool/ood-gen/bin/feed.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open Ood_gen
let term_templates =
[
("changelog", Changelog.ChangelogFeed.create_feed);
("events", Event.EventsFeed.create_feed);
("planet", Planet.GlobalFeed.create_feed);
("video", Video.create_feed);
]
Expand Down
36 changes: 36 additions & 0 deletions tool/ood-gen/lib/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,42 @@ let all () =
in
String.compare t2 t1)

module EventsFeed = struct
let create_entry (log : t) =
let authors = (Syndic.Atom.author "OCaml Events", []) in
let event_type = show_event_type log.event_type in
let textual_location = log.city ^ ", " ^ log.country in
let start_date_str =
log.starts.yyyy_mm_dd ^ "T"
^ Option.value ~default:"00:00" log.starts.utc_hh_mm
^ ":00Z"
in
let start_date = Syndic.Date.of_rfc3339 start_date_str in
let human_readable_date =
Format.sprintf "%s %d, %d"
(Syndic.Date.month start_date |> Syndic.Date.string_of_month)
(Syndic.Date.day start_date)
(Syndic.Date.year start_date)
in
let content =
Format.sprintf {|%s takes place in %s starting %s.|} log.title
textual_location human_readable_date
in
let id = Uri.of_string (log.slug ^ " " ^ start_date_str) in
Syndic.Atom.entry ~id ~authors
~title:(Syndic.Atom.Text (log.title ^ " // " ^ human_readable_date))
~updated:start_date
~links:[ Syndic.Atom.link (Uri.of_string log.url) ]
~categories:[ Syndic.Atom.category event_type ]
~content:(Syndic.Atom.Text content) ()

let create_feed () =
let open Rss in
() |> all
|> create_feed ~id:"events.xml" ~title:"OCaml Events" ~create_entry
|> feed_to_string
end

let template () =
Format.asprintf
{|
Expand Down

0 comments on commit 818c78a

Please sign in to comment.