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