d613e64f476512a261b0c7a9f3dd74086016af6d — Zach Smith 10 months ago 73d12c5
Update some Bagatto utility functins
2 files changed, 33 insertions(+), 6 deletions(-)

M bagatto.janet
M main.janet
M bagatto.janet => bagatto.janet +27 -3
@@ 63,6 63,28 @@

(defn json-attrs [src attrs] (merge-into attrs (json-data src)))

(defn- adjust-for-display [date]
  (-> (mapcat (fn [[k v]] (if (and (number? v) (find |(= $0 k) [:month-day :month :year-day :week-day]))
                          [k (inc v)]
                          [k v]))
             (pairs date))

(defn parse-date
  Given a string representation of a date or datetime, return a struct
  of the kind returned by `os/date`. Pass a truthy value in the second
  argument to adjust for human display (setting values like day and
  month to be 1-indexed).
  [datestr &opt for-display?]
  (let [parsed (-> (sh/$< date -d ,datestr "+%s")
    (if for-display? (adjust-for-display parsed) parsed)))


@@ 86,11 108,13 @@
(defn slugify
  "Normalize a string for use as a slug."
  (def not-alpha (comptime (peg/compile '(if-not (+ :w "-") 1))))
  (def space-underscore (comptime (peg/compile '(set " _"))))
  (->> s
       (string/replace-all " " "-")
       (string/replace-all "_" "-")
       (peg/replace-all space-underscore "-")
       (peg/replace-all not-alpha "")))

(defn markdown->html
  "Render a markdown string into HTML."

M main.janet => main.janet +6 -3
@@ 33,13 33,16 @@
       (util/mkpath ppath)
       (spit path contents)))))

(defn maybe-apply [f args]
(defn- maybe-apply [f args]
  (if (function? f)
    (f ;args)

(defn- struct->table [s] (->> s (kvs) (splice) (table)))
(defn- set-defaults [spec defaults] (table/setproto (struct->table spec) (struct->table defaults)))
(defn- struct->table [s]
  (->> s (kvs) (splice) (table)))

(defn- set-defaults [spec defaults]
  (table/setproto (struct->table spec) (struct->table defaults)))

(defn load-data [data-spec defaults]