diff --git a/src/app.lisp b/src/app.lisp index 88bf872..213fb90 100644 --- a/src/app.lisp +++ b/src/app.lisp @@ -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*) diff --git a/src/config/asset.lisp b/src/config/asset.lisp new file mode 100644 index 0000000..89e9f44 --- /dev/null +++ b/src/config/asset.lisp @@ -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)) diff --git a/src/config.lisp b/src/config/env.lisp similarity index 76% rename from src/config.lisp rename to src/config/env.lisp index d3e194d..4af77ac 100644 --- a/src/config.lisp +++ b/src/config/env.lisp @@ -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) diff --git a/src/config/vendor.lisp b/src/config/vendor.lisp new file mode 100644 index 0000000..40a857c --- /dev/null +++ b/src/config/vendor.lisp @@ -0,0 +1,6 @@ +(defpackage #:hp/config/vendor + (:use #:cl) + (:import-from #:log4cl)) +(in-package #:hp/config/vendor) + +(log:config :nofile) diff --git a/src/middlewares/recovery.lisp b/src/middlewares/recovery.lisp index 644f171..a1dab6f 100644 --- a/src/middlewares/recovery.lisp +++ b/src/middlewares/recovery.lisp @@ -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) diff --git a/src/routes/about.lisp b/src/routes/about.lisp index 0fbea6f..e0c319b 100644 --- a/src/routes/about.lisp +++ b/src/routes/about.lisp @@ -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" diff --git a/src/routes/index.lisp b/src/routes/index.lisp index 7592f8c..fb8bce3 100644 --- a/src/routes/index.lisp +++ b/src/routes/index.lisp @@ -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!") diff --git a/src/styles/pages/about.css b/src/styles/pages/about.css index 24c6147..bcf4ecf 100644 --- a/src/styles/pages/about.css +++ b/src/styles/pages/about.css @@ -1,4 +1,4 @@ -@scope ([data-style='pages/about']) { +@scope ([data-style='pages/about.css']) { :scope { height: 100svh; display: grid; diff --git a/src/styles/pages/index.css b/src/styles/pages/index.css index e743a0f..73420fc 100644 --- a/src/styles/pages/index.css +++ b/src/styles/pages/index.css @@ -1,4 +1,4 @@ -@scope ([data-style='pages/index']) { +@scope ([data-style='pages/index.css']) { :scope { height: 100svh; display: grid; diff --git a/src/view/asset.lisp b/src/view/asset.lisp index 810531e..e8eeb9e 100644 --- a/src/view/asset.lisp +++ b/src/view/asset.lisp @@ -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)))) diff --git a/src/view/components/document.lisp b/src/view/components/document.lisp index 9b108ed..207105e 100644 --- a/src/view/components/document.lisp +++ b/src/view/components/document.lisp @@ -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" diff --git a/src/view/renderer.lisp b/src/view/renderer.lisp index 3c6fc52..995d5c4 100644 --- a/src/view/renderer.lisp +++ b/src/view/renderer.lisp @@ -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))