Improve
This commit is contained in:
parent
baf24e7cfd
commit
c13a47f2c4
4 changed files with 18 additions and 7 deletions
src
|
@ -1,6 +1,7 @@
|
||||||
(defpackage #:hp/config/asset
|
(defpackage #:hp/config/asset
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:export #:*asset-roots*))
|
(:export #:*asset-roots*
|
||||||
|
#:*hx-ext*))
|
||||||
(in-package #:hp/config/asset)
|
(in-package #:hp/config/asset)
|
||||||
|
|
||||||
(defparameter *asset-roots*
|
(defparameter *asset-roots*
|
||||||
|
@ -10,3 +11,6 @@
|
||||||
:vendor "/vendor/"
|
:vendor "/vendor/"
|
||||||
:htmx-ext "/vendor/htmx-ext/"
|
:htmx-ext "/vendor/htmx-ext/"
|
||||||
:alpine-ext "/vendor/alpine-ext/"))
|
:alpine-ext "/vendor/alpine-ext/"))
|
||||||
|
|
||||||
|
(defparameter *hx-ext*
|
||||||
|
"head-support,alpine-morph")
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
(:export #:*assets-server*))
|
(:export #:*assets-server*))
|
||||||
(in-package #:hp/middlewares/assets-server)
|
(in-package #:hp/middlewares/assets-server)
|
||||||
|
|
||||||
(defun exist-public-file-p (path)
|
(defun exist-asset-file-p (path)
|
||||||
(let ((pathname (probe-file (concatenate 'string "assets" path))))
|
(let ((pathname (probe-file (concatenate 'string "assets" path))))
|
||||||
(and pathname (pathname-name pathname))))
|
(and pathname (pathname-name pathname))))
|
||||||
|
|
||||||
|
@ -14,5 +14,5 @@
|
||||||
(funcall *lack-middleware-static*
|
(funcall *lack-middleware-static*
|
||||||
app
|
app
|
||||||
:path (lambda (path)
|
:path (lambda (path)
|
||||||
(and (exist-public-file-p path) path))
|
(and (exist-asset-file-p path) path))
|
||||||
:root (asdf:system-relative-pathname :hp "assets/"))))
|
:root (asdf:system-relative-pathname :hp "assets/"))))
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
(defpackage #:hp/view/components/layout/main
|
(defpackage #:hp/view/components/layout/main
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:local-nicknames (#:pi #:piccolo))
|
(:local-nicknames (#:pi #:piccolo))
|
||||||
|
(:local-nicknames (#:cfg #:hp/config/asset))
|
||||||
(:export #:layout))
|
(:export #:layout))
|
||||||
(in-package #:hp/view/components/layout/main)
|
(in-package #:hp/view/components/layout/main)
|
||||||
|
|
||||||
(pi:define-element layout ()
|
(pi:define-element layout ()
|
||||||
(pi:h
|
(pi:h
|
||||||
(body
|
(body
|
||||||
:hx-ext "head-support,alpine-morph"
|
:hx-ext cfg:*hx-ext*
|
||||||
:x-data t
|
:x-data t
|
||||||
:|:data-dark| "$store.darkMode.on"
|
:|:data-dark| "$store.darkMode.on"
|
||||||
; header
|
; header
|
||||||
|
|
|
@ -2,18 +2,24 @@
|
||||||
(:use #:cl)
|
(:use #:cl)
|
||||||
(:local-nicknames (#:jg #:jingle))
|
(:local-nicknames (#:jg #:jingle))
|
||||||
(:local-nicknames (#:pi #:piccolo))
|
(:local-nicknames (#:pi #:piccolo))
|
||||||
|
(:local-nicknames (#:cfg #:hp/config/env))
|
||||||
(:local-nicknames (#:cmp #:hp/view/components/**/*))
|
(:local-nicknames (#:cmp #:hp/view/components/**/*))
|
||||||
(:export #:render
|
(:export #:render
|
||||||
#:partial-render))
|
#:partial-render))
|
||||||
(in-package #:hp/view/renderer)
|
(in-package #:hp/view/renderer)
|
||||||
|
|
||||||
|
(defun renderer ()
|
||||||
|
(if (cfg:dev-mode-p)
|
||||||
|
#'pi:element-string
|
||||||
|
#'pi:elem-str))
|
||||||
|
|
||||||
(defun render (page &key status metadata)
|
(defun render (page &key status metadata)
|
||||||
(jg:with-html-response
|
(jg:with-html-response
|
||||||
(if status (jg:set-response-status status))
|
(if status (jg:set-response-status status))
|
||||||
(pi:elem-str (cmp:document :metadata metadata
|
(funcall (renderer) (cmp:document :metadata metadata
|
||||||
(cmp:layout page)))))
|
(cmp:layout page)))))
|
||||||
|
|
||||||
(defun partial-render (component &key status)
|
(defun partial-render (component &key status)
|
||||||
(jg:with-html-response
|
(jg:with-html-response
|
||||||
(if status (jg:set-response-status status))
|
(if status (jg:set-response-status status))
|
||||||
(pi:elem-str (cmp:partial-document component))))
|
(funcall (renderer) (cmp:partial-document component))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue