;; Blog link-card fragment handler
;;
;; Renders link-card(s) for blog posts by slug.
;; Supports single mode (?slug=x) and batch mode (?keys=x,y,z).

(defhandler link-card (&key slug keys)
  (if keys
    (let ((slugs (split keys ",")))
      (<> (map (fn (s)
        (let ((post (query "blog" "post-by-slug" :slug (trim s))))
          (when post
            (<> (str "<!-- fragment:" (trim s) " -->")
                (~link-card
                  :link (app-url "blog" (str "/" (get post "slug") "/"))
                  :title (get post "title")
                  :image (get post "feature_image")
                  :icon "fas fa-file-alt"
                  :subtitle (or (get post "custom_excerpt") (get post "excerpt"))
                  :detail (get post "published_at_display")
                  :data-app "blog"))))) slugs)))
    (when slug
      (let ((post (query "blog" "post-by-slug" :slug slug)))
        (when post
          (~link-card
            :link (app-url "blog" (str "/" (get post "slug") "/"))
            :title (get post "title")
            :image (get post "feature_image")
            :icon "fas fa-file-alt"
            :subtitle (or (get post "custom_excerpt") (get post "excerpt"))
            :detail (get post "published_at_display")
            :data-app "blog"))))))
