go: redo asset handling
All checks were successful
continuous-integration/drone/push Build is passing

* only embed substructure of assets
* create subfolders for css, imgs
* add .gitattributes file specifying pcmt.css as generated (by tailwind)
This commit is contained in:
leo 2023-05-08 00:13:33 +02:00
parent 1b2679ad97
commit df0c280ad1
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
16 changed files with 22 additions and 18 deletions

@ -47,7 +47,7 @@ steps:
commands:
- pacman -Sy && pacman -S --noconfirm --needed npm
- npm i
- npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify
- npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --minify
- name: go build
image: docker.io/immawanderer/archlinux-go:linux-amd64
@ -119,7 +119,7 @@ steps:
commands:
- apk update -q && apk add -q --no-cache npm
- npm i
- npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify
- npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --minify
- name: go build
image: docker.io/library/golang:1.20.4-alpine3.17

3
.gitattributes vendored Normal file

@ -0,0 +1,3 @@
* text=auto eol=lf
/assets/public/css/pcmt.css linguist-generated

4
.gitignore vendored

@ -9,8 +9,8 @@ pcmt
# 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
# running the application, using either go generate or directly using npm.
/assets/public/css/pcmt.css
/node_modules/

@ -55,7 +55,8 @@ func (a *App) Init(s *settings.Settings, logger *slogging.Logger, dbclient *ent.
}
if a.assetsPath == "" {
a.assetsPath = "assets"
a.logger.Debug("setting assets path as unset")
a.assetsPath = "assets/public"
a.setting.SetAssetsPath("assets")
} else {
a.setting.SetAssetsPath(a.assetsPath)

@ -29,7 +29,7 @@ func (a *App) getAssets() http.FileSystem {
a.logger.Info("assets loaded in embed mode")
fsys, err := fs.Sub(a.embeds.assets, "assets")
fsys, err := fs.Sub(a.embeds.assets, "assets/public")
if err != nil {
panic(err)
}

@ -40,7 +40,7 @@ func TestStaticRoute(t *testing.T) {
setting := settings.New()
a := &App{
templatesPath: "../templates",
assetsPath: "../assets",
assetsPath: "../assets/public",
}
log := slogging.Init(false)
tstRoute := "/static/"
@ -93,7 +93,7 @@ func BenchmarkStatic(b *testing.B) {
setting := settings.New()
a := &App{
templatesPath: "../templates",
assetsPath: "../assets",
assetsPath: "../assets/public",
}
log := slogging.Init(false)
db := enttest.Open(b, "sqlite3", connstr)
@ -125,7 +125,7 @@ func BenchmarkStatic2(b *testing.B) {
setting := settings.New()
a := &App{
templatesPath: "../templates",
assetsPath: "../assets",
assetsPath: "../assets/public",
}
log := slogging.Init(false)
db := enttest.Open(b, "sqlite3", connstr)

Before

Width:  |  Height:  |  Size: 339 B

After

Width:  |  Height:  |  Size: 339 B

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Before

Width:  |  Height:  |  Size: 339 B

After

Width:  |  Height:  |  Size: 339 B

2
bs.js

@ -17,7 +17,7 @@ module.exports = {
"port": 3003
},
/* "files": true, */
"files": ["templates/*.tmpl", "assets/*.css"],
"files": ["templates/*.tmpl", "assets/input/css/*.css"],
"watchEvents": [
"change"
],

@ -6,6 +6,6 @@ var (
//go:embed all:templates
templates embed.FS
//go:embed assets assets/img
//go:embed all:assets/public
assets embed.FS
)

2
gen.go

@ -1,4 +1,4 @@
package main
//go:generate npm i
//go:generate npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify
//go:generate npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --minify

@ -1,7 +1,7 @@
# run tailwindcss tool in watch mode.
watch-tw:
npm i
npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --watch
npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --watch
# start browser-sync.
watch-brs:
@ -11,7 +11,7 @@ watch-brs:
# build app stylesheets using the tailwindcss cli tool.
tw:
npm i
npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify
npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --minify
# build the application.
build:

@ -5,8 +5,8 @@
"tailwindcss": "^3.3.0"
},
"scripts": {
"watch-tw": "npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --watch",
"watch-tw": "npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --watch",
"watch-brs": "npx browser-sync start --config bs.js",
"tw": "npx tailwindcss -i ./assets/input.css -o ./assets/pcmt.css --minify"
"tw": "npx tailwindcss -i ./assets/input/css/tailwind.css -o ./assets/public/css/pcmt.css --minify"
}
}

@ -17,8 +17,8 @@
<meta property="og:type" content="website">
<link rel="icon" href="/assets/img/logo-pcmt.svg" type="image/svg+xml">
<link href="/assets/pcmt.css" rel="preload" as="style">
<link href="/assets/pcmt.css" rel="stylesheet">
<link href="/assets/css/pcmt.css" rel="preload" as="style">
<link href="/assets/css/pcmt.css" rel="stylesheet">
{{- if .DevelMode -}}
<!-- <link href="http://localhost:3002/browser-sync/browser-sync-client.js?v=2.29.1" rel="preload" as="script"> -->