Improve assets
This commit is contained in:
parent
544cbfcb6a
commit
0e0ecf294b
4 changed files with 20 additions and 22 deletions
src
|
@ -26,8 +26,8 @@
|
||||||
(fbr:assign-routes *app*
|
(fbr:assign-routes *app*
|
||||||
:system "hp"
|
:system "hp"
|
||||||
:directory "src/routes")
|
:directory "src/routes")
|
||||||
(jg:install-middleware *app* mw:*serve-assets*)
|
|
||||||
(jg:install-middleware *app* mw:*recovery*)
|
(jg:install-middleware *app* mw:*recovery*)
|
||||||
|
(jg:install-middleware *app* mw:*serve-assets*)
|
||||||
(jg:install-middleware *app* mw:*normalize-path*)
|
(jg:install-middleware *app* mw:*normalize-path*)
|
||||||
(jg:install-middleware *app* mw:*accesslog*)
|
(jg:install-middleware *app* mw:*accesslog*)
|
||||||
(jg:install-middleware *app* mw:*block-unsupported-browser*))
|
(jg:install-middleware *app* mw:*block-unsupported-browser*))
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
(pi:define-element page ()
|
(pi:define-element page ()
|
||||||
(pi:h
|
(pi:h
|
||||||
(section (view:asset-props :style "pages/about.css"
|
(section (view:asset-props :css "pages/about.css"
|
||||||
:script "pages/about.js"
|
:js "pages/about.js"
|
||||||
:x-data "aboutPage")
|
:x-data "aboutPage")
|
||||||
(h1 "About")
|
(h1 "About")
|
||||||
(a :href "/" :hx-boost "true"
|
(a :href "/" :hx-boost "true"
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
(pi:define-element page ()
|
(pi:define-element page ()
|
||||||
(pi:h
|
(pi:h
|
||||||
(section (view:asset-props :style "pages/index.css"
|
(section (view:asset-props :css "pages/index.css"
|
||||||
:script "pages/index.js"
|
:js "pages/index.js"
|
||||||
:x-data "indexPage")
|
:x-data "indexPage")
|
||||||
(h1
|
(h1
|
||||||
"Hello, World!")
|
"Hello, World!")
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
(lambda (path)
|
(lambda (path)
|
||||||
(asset-path kind path)))
|
(asset-path kind path)))
|
||||||
|
|
||||||
(defmacro define-asset (name kind &body files)
|
(defmacro define-asset (name kind files)
|
||||||
`(defparameter ,name
|
`(defparameter ,name
|
||||||
(funcall ,(if (rest files) '#'identity '#'car)
|
(,(if (listp files) 'mapcar 'funcall)
|
||||||
(mapcar (asset-path-under ,kind) ',files))))
|
(asset-path-under ,kind) ',files)))
|
||||||
|
|
||||||
(define-asset *ress* :vendor
|
(define-asset *ress* :vendor
|
||||||
"ress@5.0.2.css")
|
"ress@5.0.2.css")
|
||||||
|
@ -46,31 +46,29 @@
|
||||||
(define-asset *htmx* :vendor
|
(define-asset *htmx* :vendor
|
||||||
"htmx@1.9.12.js")
|
"htmx@1.9.12.js")
|
||||||
(define-asset *htmx-extentions* :htmx-ext
|
(define-asset *htmx-extentions* :htmx-ext
|
||||||
"alpine-morph@1.9.12.js"
|
("alpine-morph@1.9.12.js"
|
||||||
"head-support@1.9.12.js")
|
"head-support@1.9.12.js"))
|
||||||
|
|
||||||
(define-asset *alpine* :vendor
|
(define-asset *alpine* :vendor
|
||||||
"alpine@3.13.8.js")
|
"alpine@3.13.8.js")
|
||||||
(define-asset *alpine-extentions* :alpine-ext
|
(define-asset *alpine-extentions* :alpine-ext
|
||||||
"async-alpine@1.2.2.js"
|
("async-alpine@1.2.2.js"
|
||||||
"persist@3.13.8.js"
|
"persist@3.13.8.js"
|
||||||
"morph@3.13.8.js")
|
"morph@3.13.8.js"))
|
||||||
|
|
||||||
(defun detect-data-props (html-str data-prop-name)
|
(defun detect-data-props (html-str data-prop-name)
|
||||||
(remove-duplicates (re:all-matches-as-strings (format nil
|
(let* ((regex (format nil "(?<=~a=\")[^\"]*(?=\")" data-prop-name))
|
||||||
"(?<=~a=\")[^\"]*(?=\")"
|
(data-props (re:all-matches-as-strings regex html-str)))
|
||||||
data-prop-name)
|
(remove-duplicates data-props :test #'string=)))
|
||||||
html-str)
|
|
||||||
:test #'string=))
|
|
||||||
|
|
||||||
(defun get-css-paths (html-str)
|
(defun get-css-paths (html-str)
|
||||||
(mapcar (asset-path-under :css)
|
(mapcar (asset-path-under :css)
|
||||||
(detect-data-props html-str "data-style")))
|
(detect-data-props html-str "data-style")))
|
||||||
|
|
||||||
(defun asset-props (&key style script x-data)
|
(defun asset-props (&key css js x-data)
|
||||||
(append (and style `(:data-style ,style))
|
(append (and css `(:data-style ,css))
|
||||||
(and script x-data
|
(and js x-data
|
||||||
`(:ax-load t
|
`(:ax-load t
|
||||||
:ax-load-src ,(asset-path :js script)
|
:ax-load-src ,(asset-path :js js)
|
||||||
:x-ignore t
|
:x-ignore t
|
||||||
:x-data ,x-data))))
|
:x-data ,x-data))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue