2025-05-02 09:39:55 +09:00
|
|
|
(defpackage #:website/renderer
|
2024-06-15 21:59:15 +09:00
|
|
|
(:use #:cl
|
2024-11-16 01:52:01 +09:00
|
|
|
#:hsx
|
|
|
|
#:trivia)
|
2025-03-29 14:48:36 +09:00
|
|
|
(:import-from #:jingle
|
|
|
|
#:set-response-header)
|
2024-11-16 01:52:01 +09:00
|
|
|
(:import-from #:hsx/element
|
2025-03-29 12:01:07 +09:00
|
|
|
#:element)
|
2025-05-02 09:39:55 +09:00
|
|
|
(:import-from #:website/lib/env
|
|
|
|
#:website-url
|
|
|
|
#:website-env)
|
|
|
|
(:import-from #:website/components/layout
|
2025-04-29 18:04:02 +09:00
|
|
|
#:~layout))
|
2025-05-02 09:39:55 +09:00
|
|
|
(in-package #:website/renderer)
|
2024-06-01 22:21:15 +09:00
|
|
|
|
2025-05-01 00:37:46 +09:00
|
|
|
(defun set-cache-control (strategy)
|
|
|
|
(set-response-header :cache-control
|
2025-05-02 09:39:55 +09:00
|
|
|
(if (string= (website-env) "dev")
|
2025-05-01 00:37:46 +09:00
|
|
|
"private, no-store"
|
|
|
|
(cond
|
2025-05-02 11:20:37 +09:00
|
|
|
((eq strategy :static) "public, max-age=60, s-maxage=31536000")
|
2025-05-01 23:25:28 +09:00
|
|
|
((eq strategy :dynamic) "public, max-age=60")
|
|
|
|
(t "private, no-store")))))
|
2025-05-01 00:37:46 +09:00
|
|
|
|
2025-03-29 01:07:45 +09:00
|
|
|
(defmethod jingle:process-response ((app jingle:app) result)
|
2025-03-29 14:48:36 +09:00
|
|
|
(set-response-header :content-type "text/html; charset=utf-8")
|
2025-05-03 08:18:51 +09:00
|
|
|
(match result
|
|
|
|
((plist :body body
|
|
|
|
:metadata metadata
|
|
|
|
:cache cache
|
|
|
|
:partial partial)
|
|
|
|
(set-cache-control cache)
|
|
|
|
(call-next-method app
|
|
|
|
(hsx:render-to-string
|
|
|
|
(if partial
|
|
|
|
body
|
|
|
|
(~layout :metadata metadata
|
|
|
|
body)))))
|
|
|
|
(_ (error "Invalid response form"))))
|