Simplify rendering

This commit is contained in:
Akira Tempaku 2025-05-03 21:06:39 +09:00
parent 6e72b82307
commit 1b217da311
Signed by: paku
GPG key ID: 5B4E8402BCC50607
6 changed files with 18 additions and 38 deletions

View file

@ -39,34 +39,23 @@
(script :src "https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.1/dist/preload.min.js") (script :src "https://cdn.jsdelivr.net/npm/htmx-ext-preload@2.1.1/dist/preload.min.js")
(script :src "https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.4/dist/head-support.min.js") (script :src "https://cdn.jsdelivr.net/npm/htmx-ext-head-support@2.0.4/dist/head-support.min.js")
(script :src "https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.3/dist/response-targets.min.js") (script :src "https://cdn.jsdelivr.net/npm/htmx-ext-response-targets@2.0.3/dist/response-targets.min.js")
(script :src "https://cdn.jsdelivr.net/npm/htmx-ext-alpine-morph@2.0.1/alpine-morph.min.js") ;(script :src "https://cdn.jsdelivr.net/npm/htmx-ext-alpine-morph@2.0.1/alpine-morph.min.js")
(script :src "https://cdn.jsdelivr.net/npm/@alpinejs/morph@3.14.9/dist/cdn.min.js" :defer t) ;(script :src "https://cdn.jsdelivr.net/npm/@alpinejs/morph@3.14.9/dist/cdn.min.js" :defer t)
(script :src "https://cdn.jsdelivr.net/npm/alpinejs@3.14.9/dist/cdn.min.js" :defer t)) (script :src "https://cdn.jsdelivr.net/npm/alpinejs@3.14.9/dist/cdn.min.js" :defer t))
children))) children)))
(defun set-cache-control (strategy)
(set-response-header :cache-control
(if (string= (website-env) "dev")
"private, no-store"
(cond
((eq strategy :static) "public, max-age=60, s-maxage=604800, immutable")
((eq strategy :dynamic) "public, max-age=60")
(t "private, no-store")))))
(defmethod jingle:process-response ((app jingle:app) result) (defmethod jingle:process-response ((app jingle:app) result)
(set-response-header :content-type "text/html; charset=utf-8") (set-response-header :content-type "text/html; charset=utf-8")
(set-response-header :cache-control (if (string= (website-env) "dev")
"private, no-store"
"public, max-age=60"))
(match result (match result
((plist :body body ((guard (or (list body metadata)
:metadata metadata body)
:cache cache (typep body 'element))
:partial partial)
(set-cache-control cache)
(call-next-method app (call-next-method app
(hsx:render-to-string (hsx:render-to-string
(if partial (~document :metadata metadata
body (~layout
(~document :metadata metadata body)))))
(~layout
body))))))
(_ (error "Invalid response form")))) (_ (error "Invalid response form"))))

View file

@ -19,6 +19,4 @@
(defun handle-get (params) (defun handle-get (params)
(declare (ignore params)) (declare (ignore params))
(list :body (~page) (list (~page) *metadata*))
:metadata *metadata*
:cache :dynamic))

View file

@ -10,10 +10,8 @@
(defcomp ~page () (defcomp ~page ()
(hsx (hsx
(p "coming soon"))) (p "coming soon")))
(defun handle-get (params) (defun handle-get (params)
(declare (ignore params)) (declare (ignore params))
(list :body (~page) (list (~page) *metadata*))
:metadata *metadata*
:cache :dynamic))

View file

@ -43,8 +43,7 @@
(defun handle-get (params) (defun handle-get (params)
(declare (ignore params)) (declare (ignore params))
(list :body (~page) (~page))
:cache :static))
; for health check ; for health check
(defun handle-head (params) (defun handle-head (params)

View file

@ -18,6 +18,4 @@
"Back to TOP")))) "Back to TOP"))))
(defun handle-not-found () (defun handle-not-found ()
(list :body (~page) (list (~page) *metadata*))
:metadata *metadata*
:cache :dynamic))

View file

@ -15,10 +15,8 @@
(defcomp ~page () (defcomp ~page ()
(hsx (hsx
(p "coming soon"))) (p "coming soon")))
(defun handle-get (params) (defun handle-get (params)
(declare (ignore params)) (declare (ignore params))
(list :body (~page) (list (~page) *metadata*))
:metadata *metadata*
:cache :dynamic))