From 1655d6b79244a4ca42019c08600539efe14e9227 Mon Sep 17 00:00:00 2001 From: leo <wanderer@dotya.ml> Date: Wed, 26 Apr 2023 22:44:18 +0200 Subject: [PATCH] go: /static -> /assets in varnames,routes,dirs --- .gitignore | 6 ++++-- app/assets.go | 4 ++-- app/routes.go | 11 ++++++++++- bs.js | 2 +- justfile | 6 ++---- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 4c8cb8c..0fef018 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,10 @@ pcmt # air tmp dir /tmp -# static assets folder -/static/ +# this stylesheet gets dynamically rebuilt and is therefore not a stable thing +# to stage to git. instead, users are expected to build it before compiling and +# running the application. +/assets/pcmt.css /node_modules/ diff --git a/app/assets.go b/app/assets.go index 39f61dd..a8bb54e 100644 --- a/app/assets.go +++ b/app/assets.go @@ -10,12 +10,12 @@ func (a *App) getAssets(live bool) http.FileSystem { if live { a.logger.Info("assets loaded in live mode") - return http.FS(os.DirFS("static")) + return http.FS(os.DirFS("assets")) } a.logger.Info("assets loaded in embed mode") - fsys, err := fs.Sub(a.embeds.assets, "static") + fsys, err := fs.Sub(a.embeds.assets, "assets") if err != nil { panic(err) } diff --git a/app/routes.go b/app/routes.go index 1f8addd..e37d6e8 100644 --- a/app/routes.go +++ b/app/routes.go @@ -5,6 +5,7 @@ import ( "git.dotya.ml/mirre-mt/pcmt/handlers" "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" ) func (a *App) SetupRoutes() { @@ -23,7 +24,15 @@ func (a *App) SetupRoutes() { handlers.InitHandlers(a.version, conf, tmpls) // e.GET("/", echo.WrapHandler(assetHandler)) - e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assets))) + // keep /static/* as a compatibility fallback for /assets. + e.GET( + "/static/*", + nil, + middleware.Rewrite( + map[string]string{"/static/*": "/assets/$1"}, + ), + ) + e.GET("/assets/*", echo.WrapHandler(http.StripPrefix("/assets/", assets))) // e.GET("/", handlers.Index(indexTmpl)) // e.GET("/", handlers.Index(conf, tmpls)) // e.GET("/", handlers.Index(conf)) diff --git a/bs.js b/bs.js index 1a350c6..e880a47 100644 --- a/bs.js +++ b/bs.js @@ -17,7 +17,7 @@ module.exports = { "port": 3003 }, /* "files": true, */ - "files": ["templates/*.tmpl", "dist/*.css"], + "files": ["templates/*.tmpl", "assets/*.css"], "watchEvents": [ "change" ], diff --git a/justfile b/justfile index 6dd1808..8aaec06 100644 --- a/justfile +++ b/justfile @@ -1,8 +1,7 @@ # run tailwindcss tool in watch mode. watch-tw: npm i - mkdir -pv static - npx tailwindcss -i ./assets/input.css -o ./static/pcmt.css --watch + npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --watch # start browser-sync. watch-brs: @@ -12,8 +11,7 @@ watch-brs: # build app stylesheets using the tailwindcss cli tool. tw: npm i - mkdir -p static - npx tailwindcss -i ./assets/input.css -o ./static/pcmt.css --minify + npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify # build the application. build: