SxExpr is now a str subclass so it works everywhere a plain string does (join, isinstance, f-strings) while serialize() still emits it unquoted. sx_call() and all internal render functions (_render_to_sx, async_eval_to_sx, etc.) return SxExpr, eliminating the "forgot to wrap" bug class that caused the sx_content leak and list serialization bugs. - Phase 0: SxExpr(str) with .source property, __add__/__radd__ - Phase 1: sx_call returns SxExpr (drop-in, all 200+ sites unchanged) - Phase 2: async_eval_to_sx, async_eval_slot_to_sx, _render_to_sx, mobile_menu_sx return SxExpr; remove isinstance(str) workaround - Phase 3: Remove ~150 redundant SxExpr() wrappings across 45 files - Phase 4: serialize() docstring, handler return docs, ;; returns: sx Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
2.0 KiB
Plaintext
40 lines
2.0 KiB
Plaintext
;; Container-cards fragment handler
|
|
;; returns: sx
|
|
;;
|
|
;; Returns HTML with <!-- card-widget:ID --> comment markers so the
|
|
;; blog consumer can split per-post fragments. Each post section
|
|
;; contains an events-frag-entries-widget with entry cards.
|
|
|
|
(defhandler container-cards (&key post_ids post_slugs)
|
|
(let ((ids (filter (fn (x) (> x 0))
|
|
(map parse-int
|
|
(filter (fn (s) (not (empty? s)))
|
|
(split (or post_ids "") ",")))))
|
|
(slugs (map trim
|
|
(split (or post_slugs "") ","))))
|
|
(when (not (empty? ids))
|
|
(let ((batch (service "calendar" "confirmed-entries-for-posts" :post-ids ids)))
|
|
(<> (map-indexed (fn (i pid)
|
|
(let ((entries (or (get batch pid) (list)))
|
|
(post-slug (or (nth slugs i) "")))
|
|
(<> (str "<!-- card-widget:" pid " -->")
|
|
(when (not (empty? entries))
|
|
(~events-frag-entries-widget
|
|
:cards (<> (map (fn (e)
|
|
(let ((time-str (str (format-date (get e "start_at") "%H:%M")
|
|
(if (get e "end_at")
|
|
(str " \u2013 " (format-date (get e "end_at") "%H:%M"))
|
|
""))))
|
|
(~events-frag-entry-card
|
|
:href (app-url "events"
|
|
(str "/" post-slug
|
|
"/" (get e "calendar_slug")
|
|
"/" (get e "start_at_year")
|
|
"/" (get e "start_at_month")
|
|
"/" (get e "start_at_day")
|
|
"/entries/" (get e "id") "/"))
|
|
:name (get e "name")
|
|
:date-str (format-date (get e "start_at") "%a, %b %d")
|
|
:time-str time-str))) entries))))
|
|
(str "<!-- /card-widget:" pid " -->")))) ids))))))
|