From cadd2f759d43eef883fdc5d79c2c9e58b658d384 Mon Sep 17 00:00:00 2001 From: John Krasnay Date: Tue, 17 Dec 2024 20:54:54 -0500 Subject: [PATCH] Implement initial build script --- bb.edn | 4 ++++ docs/{test.ics => clojureto.ics} | 5 +++-- docs/events/clojureto.edn | 6 ++++++ docs/index.json | 1 + src/linkup/core.clj | 30 +++++++++++++++++++++++++++--- 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 bb.edn rename docs/{test.ics => clojureto.ics} (66%) create mode 100644 docs/events/clojureto.edn create mode 100644 docs/index.json diff --git a/bb.edn b/bb.edn new file mode 100644 index 0000000..697263c --- /dev/null +++ b/bb.edn @@ -0,0 +1,4 @@ +{:paths ["src"] + :tasks + {:requires [[linkup.core :as linkup]] + build (linkup/build)}} diff --git a/docs/test.ics b/docs/clojureto.ics similarity index 66% rename from docs/test.ics rename to docs/clojureto.ics index 63f2217..c5c0fd8 100644 --- a/docs/test.ics +++ b/docs/clojureto.ics @@ -3,9 +3,10 @@ VERSION:2.0 PRODID:-//linkup//linkup//EN METHOD:PUBLISH BEGIN:VEVENT -UID: -DTSTAMP:20241218T010628Z +UID:clojureto +DTSTAMP:20241218T015254Z SUMMARY:Clojure Toronto +RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=3TU DTSTART:20241218T000000Z DTEND:20241218T020000Z END:VEVENT diff --git a/docs/events/clojureto.edn b/docs/events/clojureto.edn new file mode 100644 index 0000000..ca04c81 --- /dev/null +++ b/docs/events/clojureto.edn @@ -0,0 +1,6 @@ +{:id "clojureto" + :date "2024-12-17" + :rrule "FREQ=MONTHLY;INTERVAL=1;BYDAY=3TU" + :start-time "19:00" + :end-time "21:00" + :summary "Clojure Toronto"} diff --git a/docs/index.json b/docs/index.json new file mode 100644 index 0000000..7fe63e5 --- /dev/null +++ b/docs/index.json @@ -0,0 +1 @@ +["events/clojureto.edn"] \ No newline at end of file diff --git a/src/linkup/core.clj b/src/linkup/core.clj index 7bdfc36..3b88d75 100644 --- a/src/linkup/core.clj +++ b/src/linkup/core.clj @@ -1,5 +1,8 @@ (ns linkup.core (:require + [babashka.fs :as fs] + [cheshire.core :as json] + [clojure.edn :as edn] [clojure.string :as string]) (:import [java.time Instant LocalDate LocalTime ZonedDateTime ZoneId ZoneOffset] @@ -51,15 +54,19 @@ (defn print-time-slot [time-slot timezone] - (let [{:keys [date + (let [{:keys [id + date start-time end-time + rrule summary location]} time-slot] (vprintln "BEGIN:VEVENT") - (vprintln (str "UID:" (:id time-slot))) + (vprintln (str "UID:" id)) (vprintln (str "DTSTAMP:" (format-instant (Instant/now)))) (vprintln (str "SUMMARY:" summary)) + (when rrule + (vprintln (str "RRULE:" rrule))) (when location (vprintln (str "LOCATION:" location))) (vprintln (str "DTSTART:" (utc-time-string date start-time timezone))) @@ -78,11 +85,28 @@ (vprintln "END:VCALENDAR")) +(defn build + [] + (let [event-files (->> (fs/glob "docs/events" "*.edn") + (map str))] + (doseq [file-name event-files] + (let [[_ root] (re-find #"([^/]+).edn" file-name) + edn (-> (slurp file-name) + edn/read-string)] + (spit (str "docs/" root ".ics") + (with-out-str + (print-calendar [edn] "America/Toronto"))))) + (spit "docs/index.json" + (json/encode (->> event-files + (map (fn [s] (string/replace s "docs/" "")))))))) (comment + (re-find #"([^/]+).edn" "foo/bar/baz.edn") + (spit "docs/test.ics" (with-out-str - (print-calendar [{:date "2024-12-17" + (print-calendar [{:id "clojureto" + :date "2024-12-17" :start-time "19:00" :end-time "21:00" :summary "Clojure Toronto"