diff --git a/lib/host/blog.sx b/lib/host/blog.sx index e0ecf755..6f4f3f7a 100644 --- a/lib/host/blog.sx +++ b/lib/host/blog.sx @@ -59,12 +59,30 @@ (host/blog-slugs)))) ;; ── render ────────────────────────────────────────────────────────── -;; A post's sx_content is SX element markup -> HTML via the component renderer. +;; A post's sx_content is SX element markup -> HTML via render-page (which supplies +;; the server env so components resolve + keyword attrs are kept). +;; +;; Rendered PER BLOCK and guarded: the editor wraps content in a (<> ...) fragment +;; of blocks, some of which the host can't render (the legacy editor emits bare +;; ~kg-md cards while the components are ~kg_cards/kg-md — drift we don't paper over +;; with aliases). Rendering each block under its own guard means the real prose +;; (p/h1/ul/...) shows and only the unsupported block degrades to a placeholder — +;; and a bad block never crashes the handler (-> 502). +(define host/blog--render-node + (fn (node) + (guard (e (true "
(unsupported block)
")) + (render-page node)))) (define host/blog-render (fn (record) (let ((sx (get record :sx-content))) (if (and sx (not (= sx ""))) - (render-to-html (parse sx)) + (let ((tree (guard (e (true nil)) (parse sx)))) + (cond + ((nil? tree) "

(unparseable content)

") + ((and (= (type-of tree) "list") (> (len tree) 0) + (= (str (first tree)) "<>")) + (join "" (map host/blog--render-node (rest tree)))) + (else (host/blog--render-node tree)))) (str "

(empty post)

"))))) (define host/blog--page (fn (title body)