Improve config package
This commit is contained in:
parent
280e2e018e
commit
80139e4111
12 changed files with 56 additions and 35 deletions
src
|
@ -3,7 +3,7 @@
|
|||
(:use #:cl)
|
||||
(:local-nicknames (#:jg #:jingle))
|
||||
(:local-nicknames (#:fbr #:ningle-fbr))
|
||||
(:local-nicknames (#:cfg #:hp/config))
|
||||
(:local-nicknames (#:cfg #:hp/config/*))
|
||||
(:local-nicknames (#:mw #:hp/middlewares/*))
|
||||
(:export #:start
|
||||
#:stop
|
||||
|
@ -25,8 +25,8 @@
|
|||
(fbr:assign-routes *app*
|
||||
:system "hp"
|
||||
:directory "src/routes")
|
||||
(jg:static-path *app* "/scripts/" "src/scripts/")
|
||||
(jg:static-path *app* "/styles/" "src/styles/")
|
||||
(jg:static-path *app* (cfg:asset-root :script) "src/scripts/")
|
||||
(jg:static-path *app* (cfg:asset-root :style) "src/styles/")
|
||||
(jg:install-middleware *app* mw:*public-files*)
|
||||
(jg:install-middleware *app* mw:*recovery*)
|
||||
(jg:install-middleware *app* mw:*normalize-path*)
|
||||
|
|
16
src/config/asset.lisp
Normal file
16
src/config/asset.lisp
Normal file
|
@ -0,0 +1,16 @@
|
|||
(defpackage #:hp/config/asset
|
||||
(:use #:cl)
|
||||
(:export #:asset-root
|
||||
#:asset-path))
|
||||
(in-package #:hp/config/asset)
|
||||
|
||||
(defparameter *asset-roots*
|
||||
(list :style "/styles/"
|
||||
:script "/scripts/"
|
||||
:vendor "/vendor/"))
|
||||
|
||||
(defun asset-root (destination)
|
||||
(getf *asset-roots* destination))
|
||||
|
||||
(defun asset-path (destination path)
|
||||
(concatenate 'string (asset-root destination) path))
|
|
@ -1,10 +1,9 @@
|
|||
(defpackage #:hp/config
|
||||
(defpackage #:hp/config/env
|
||||
(:use #:cl)
|
||||
(:import-from #:log4cl)
|
||||
(:export #:dev-mode-p
|
||||
#:prod-mode-p
|
||||
#:*port*))
|
||||
(in-package #:hp/config)
|
||||
(in-package #:hp/config/env)
|
||||
|
||||
(defparameter *env* (or (uiop:getenv "HP_ENV") "dev"))
|
||||
|
||||
|
@ -15,5 +14,3 @@
|
|||
(string= *env* "prod"))
|
||||
|
||||
(defparameter *port* (parse-integer (or (uiop:getenv "HP_PORT") "3000")))
|
||||
|
||||
(log:config :nofile)
|
6
src/config/vendor.lisp
Normal file
6
src/config/vendor.lisp
Normal file
|
@ -0,0 +1,6 @@
|
|||
(defpackage #:hp/config/vendor
|
||||
(:use #:cl)
|
||||
(:import-from #:log4cl))
|
||||
(in-package #:hp/config/vendor)
|
||||
|
||||
(log:config :nofile)
|
|
@ -2,7 +2,7 @@
|
|||
(:use #:cl)
|
||||
(:import-from #:log4cl)
|
||||
(:local-nicknames (#:tb #:trivial-backtrace))
|
||||
(:local-nicknames (#:cfg #:hp/config))
|
||||
(:local-nicknames (#:cfg #:hp/config/env))
|
||||
(:export #:*recovery*))
|
||||
(in-package #:hp/middlewares/recovery)
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
(pi:define-element page ()
|
||||
(pi:h
|
||||
(section (view:asset-props :style "pages/about"
|
||||
:script "pages/about"
|
||||
(section (view:asset-props :style "pages/about.css"
|
||||
:script "pages/about.js"
|
||||
:x-data "aboutPageState")
|
||||
(h1 "About")
|
||||
(a :href "/" :hx-boost "true"
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
(pi:define-element page ()
|
||||
(pi:h
|
||||
(section (view:asset-props :style "pages/index"
|
||||
:script "pages/index"
|
||||
(section (view:asset-props :style "pages/index.css"
|
||||
:script "pages/index.js"
|
||||
:x-data "indexPageState")
|
||||
(h1
|
||||
"Hello, World!")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@scope ([data-style='pages/about']) {
|
||||
@scope ([data-style='pages/about.css']) {
|
||||
:scope {
|
||||
height: 100svh;
|
||||
display: grid;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@scope ([data-style='pages/index']) {
|
||||
@scope ([data-style='pages/index.css']) {
|
||||
:scope {
|
||||
height: 100svh;
|
||||
display: grid;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
(defpackage #:hp/view/asset
|
||||
(:use #:cl)
|
||||
(:local-nicknames (#:re #:cl-ppcre))
|
||||
(:local-nicknames (#:cfg #:hp/config/asset))
|
||||
(:export #:get-css-links
|
||||
#:asset-props))
|
||||
(in-package #:hp/view/asset)
|
||||
|
@ -12,20 +13,15 @@
|
|||
html-str)
|
||||
:test #'string=))
|
||||
|
||||
(defun data-props->asset-links (parent-path extension data-props)
|
||||
(mapcar (lambda (data-prop)
|
||||
(concatenate 'string parent-path data-prop extension))
|
||||
data-props))
|
||||
|
||||
(defun get-css-links (html-str)
|
||||
(data-props->asset-links "/styles/"
|
||||
".css"
|
||||
(detect-data-props html-str "data-style")))
|
||||
(mapcar (lambda (data-prop)
|
||||
(cfg:asset-path :style data-prop))
|
||||
(detect-data-props html-str "data-style")))
|
||||
|
||||
(defun asset-props (&key style script x-data)
|
||||
(append (and style `(:data-style ,style))
|
||||
(and script x-data
|
||||
`(:ax-load t
|
||||
:ax-load-src ,(format nil "/scripts/~a.js" script)
|
||||
:ax-load-src ,(cfg:asset-path :script script)
|
||||
:x-ignore t
|
||||
:x-data ,x-data))))
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(:use #:cl)
|
||||
(:local-nicknames (#:pi #:piccolo))
|
||||
(:local-nicknames (#:asset #:hp/view/asset))
|
||||
(:local-nicknames (#:cfg #:hp/config/asset))
|
||||
(:export #:document
|
||||
#:partial-document))
|
||||
(in-package #:hp/view/components/document)
|
||||
|
@ -20,22 +21,28 @@
|
|||
(html :lang "ja"
|
||||
(head
|
||||
(meta :charset "UTF-8")
|
||||
(link :rel "stylesheet" :type "text/css" :href "/vendor/ress@5.0.2.css")
|
||||
(link :rel "stylesheet" :type "text/css" :href "/styles/global.css")
|
||||
(link
|
||||
:rel "stylesheet"
|
||||
:type "text/css"
|
||||
:href (cfg:asset-path :vendor "ress@5.0.2.css"))
|
||||
(link
|
||||
:rel "stylesheet"
|
||||
:type "text/css"
|
||||
:href (cfg:asset-path :style "global.css"))
|
||||
(on-demand-stylesheets pi:children)
|
||||
(link :rel "preconnect" :href "https://fonts.googleapis.com")
|
||||
(link :rel "preconnect" :href "https://fonts.gstatic.com" :crossorigin t)
|
||||
(link
|
||||
:rel "stylesheet"
|
||||
:href "https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap")
|
||||
(script :src "/vendor/htmx@1.9.12.js")
|
||||
(script :src "/vendor/htmx-ext/alpine-morph@1.9.12.js")
|
||||
(script :src "/vendor/htmx-ext/head-support@1.9.12.js")
|
||||
(script :src "/vendor/alpine-ext/async-alpine@1.2.2.js" :defer t)
|
||||
(script :src "/vendor/alpine-ext/persist@3.13.8.js" :defer t)
|
||||
(script :src "/vendor/alpine-ext/morph@3.13.8.js" :defer t)
|
||||
(script :src "/scripts/global.js" :defer t)
|
||||
(script :src "/vendor/alpine@3.13.8.js" :defer t)
|
||||
(script :src (cfg:asset-path :vendor "htmx@1.9.12.js"))
|
||||
(script :src (cfg:asset-path :vendor "htmx-ext/alpine-morph@1.9.12.js"))
|
||||
(script :src (cfg:asset-path :vendor "htmx-ext/head-support@1.9.12.js"))
|
||||
(script :src (cfg:asset-path :vendor "alpine-ext/async-alpine@1.2.2.js") :defer t)
|
||||
(script :src (cfg:asset-path :vendor "alpine-ext/persist@3.13.8.js") :defer t)
|
||||
(script :src (cfg:asset-path :vendor "alpine-ext/morph@3.13.8.js") :defer t)
|
||||
(script :src (cfg:asset-path :script "global.js") :defer t)
|
||||
(script :src (cfg:asset-path :vendor "alpine@3.13.8.js") :defer t)
|
||||
(title (format nil "~@[~a - ~]skyizwhite.dev" title))
|
||||
(meta
|
||||
:name "description"
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
(:use #:cl)
|
||||
(:local-nicknames (#:jg #:jingle))
|
||||
(:local-nicknames (#:pi #:piccolo))
|
||||
(:local-nicknames (#:cfg #:hp/config))
|
||||
(:local-nicknames (#:cmp #:hp/view/components/*))
|
||||
(:export #:render
|
||||
#:partial-render))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue