Improve response package
This commit is contained in:
parent
79ee7c5e14
commit
940852c4f2
5 changed files with 27 additions and 41 deletions
src
0
src/components/.keep
Normal file
0
src/components/.keep
Normal file
|
@ -1,22 +0,0 @@
|
|||
(defpackage #:hp/components/document
|
||||
(:use #:cl
|
||||
#:hsx)
|
||||
(:export #:document))
|
||||
(in-package #:hp/components/document)
|
||||
|
||||
(defcomp document (&key title description children)
|
||||
(hsx
|
||||
(html :lang "ja"
|
||||
(head
|
||||
(meta :charset "UTF-8")
|
||||
(meta :name "viewport" :content "width=device-width, initial-scale=1")
|
||||
(link :rel "stylesheet" :href "https://cdn.jsdelivr.net/npm/uikit@3.21.5/dist/css/uikit.min.css")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/uikit@3.21.5/dist/js/uikit.min.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/htmx.org@1.9.12/dist/htmx.min.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/htmx.org@1.9.12/dist/ext/head-support.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/alpinejs@3.14.0/dist/cdn.min.js" :defer t)
|
||||
(title (format nil "~@[~a - ~]skyizwhite.dev" title))
|
||||
(meta
|
||||
:name "description"
|
||||
:content (or description "pakuの個人サイト")))
|
||||
children)))
|
|
@ -1,11 +0,0 @@
|
|||
(defpackage #:hp/components/layout
|
||||
(:use #:cl
|
||||
#:hsx)
|
||||
(:export #:layout))
|
||||
(in-package #:hp/components/layout)
|
||||
|
||||
(defcomp layout (&key children)
|
||||
(hsx
|
||||
(body :hx-ext "head-support"
|
||||
(main :class "uk-container"
|
||||
children))))
|
|
@ -16,6 +16,5 @@
|
|||
(handler-case
|
||||
(funcall app env)
|
||||
(error (c)
|
||||
(log:error "Unhandled error caught: ~a" c)
|
||||
`(500 (:content-type "text/plain")
|
||||
(,(message c))))))))
|
||||
|
|
|
@ -1,19 +1,39 @@
|
|||
(defpackage #:hp/response
|
||||
(:use #:cl)
|
||||
(:import-from #:hsx)
|
||||
(:use #:cl
|
||||
#:hsx)
|
||||
(:local-nicknames (#:jg #:jingle))
|
||||
(:local-nicknames (#:cmp #:hp/components/*))
|
||||
(:export #:response
|
||||
#:partial-response))
|
||||
(in-package #:hp/response)
|
||||
|
||||
(defcomp document (&key title description children)
|
||||
(hsx
|
||||
(html :lang "ja"
|
||||
(head
|
||||
(meta :charset "UTF-8")
|
||||
(meta :name "viewport" :content "width=device-width, initial-scale=1")
|
||||
(link :rel "stylesheet" :href "https://cdn.jsdelivr.net/npm/uikit@3.21.5/dist/css/uikit.min.css")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/uikit@3.21.5/dist/js/uikit.min.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/htmx.org@1.9.12/dist/htmx.min.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/htmx.org@1.9.12/dist/ext/head-support.js")
|
||||
(script :src "https://cdn.jsdelivr.net/npm/alpinejs@3.14.0/dist/cdn.min.js" :defer t)
|
||||
(title (format nil "~@[~a - ~]skyizwhite.dev" title))
|
||||
(meta
|
||||
:name "description"
|
||||
:content (or description "pakuの個人サイト"))
|
||||
(body :hx-ext "head-support"
|
||||
(main :class "uk-container"
|
||||
children))))))
|
||||
|
||||
(defun response (page &key status metadata)
|
||||
(jg:with-html-response
|
||||
(if status (jg:set-response-status status))
|
||||
(hsx:render-to-string (cmp:document metadata
|
||||
(cmp:layout page)))))
|
||||
(when status
|
||||
(jg:set-response-status status))
|
||||
(hsx:render-to-string (document metadata
|
||||
page))))
|
||||
|
||||
(defun partial-response (component &key status)
|
||||
(jg:with-html-response
|
||||
(if status (jg:set-response-status status))
|
||||
(when status
|
||||
(jg:set-response-status status))
|
||||
(hsx:render-to-string component)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue