;; content-on-sx — list-card summary projection.
;;
;; content/summary returns a one-call projection for index/listing cards:
;;   {:id :title :excerpt :words :reading-minutes :cover}
;; composing the metadata, text, stats and query layers. `cover` is the first
;; image's src (or nil).
;;
;; Requires (loaded by harness): doc.sx, meta.sx (doc-title), text.sx
;; (content/excerpt), stats.sx (word-count/reading), query.sx (select-type).

(define
  content/summary-title
  (fn (doc) (let ((t (doc-title doc))) (if (= t nil) (doc-id doc) t))))

(define
  content/cover
  (fn
    (doc)
    (let
      ((imgs (content/select-type doc "image")))
      (if
        (= (len imgs) 0)
        nil
        (str (blk-get (first imgs) "src"))))))

(define content/summary (fn (doc) {:id (doc-id doc) :reading-minutes (content/reading-minutes doc) :words (content/word-count doc) :title (content/summary-title doc) :excerpt (content/excerpt doc 160) :cover (content/cover doc)}))
