Optimized CSS Gen
This commit is contained in:
@ -15,7 +15,7 @@ tmp_dir = "tmp"
|
||||
follow_symlink = false
|
||||
full_bin = ""
|
||||
include_dir = []
|
||||
include_ext = ["go", "tpl", "tmpl", "html"]
|
||||
include_ext = ["go", "tpl", "tmpl", "html", "css"]
|
||||
include_file = []
|
||||
kill_delay = "0s"
|
||||
log = "build-errors.log"
|
||||
|
@ -5,3 +5,4 @@
|
||||
**/*.rdb
|
||||
**/stylegen/**
|
||||
fly.toml
|
||||
tailwind.config.*.js
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@ goth.stack
|
||||
.env
|
||||
airbin
|
||||
tmp/
|
||||
*.rdb
|
||||
*.rdb
|
||||
tailwind.config.*.js
|
5
main.go
5
main.go
@ -60,7 +60,10 @@ func main() {
|
||||
|
||||
// Static server
|
||||
fs := http.FS(PublicFS)
|
||||
e.GET("/public/*", echo.WrapHandler(http.FileServer(fs)))
|
||||
e.GET("/public/*", func(c echo.Context) error {
|
||||
c.Response().Header().Set("Cache-Control", "public, max-age=3600")
|
||||
return echo.WrapHandler(http.FileServer(fs))(c)
|
||||
})
|
||||
|
||||
// Page routes
|
||||
e.GET("/", pages.Home)
|
||||
|
@ -7,6 +7,7 @@ GOTH // Blog
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.blog.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
@ -7,6 +7,7 @@ GOTH // Home
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.home.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
@ -7,7 +7,6 @@
|
||||
<link rel="icon" href="/public/favicon.ico" />
|
||||
<title>{{template "title" .}}</title>
|
||||
<meta name="description" content="Just here for the vibes...">
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{template "head" .}}
|
||||
</head>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<link rel="icon" href="/public/favicon.ico" />
|
||||
<title>{{.Name}}</title>
|
||||
<meta name="description" content="Just here for the vibes...">
|
||||
<link rel="stylesheet" href="/public/css/styles.css" />
|
||||
{{template "head" .}}
|
||||
</head>
|
||||
|
||||
<body class="block h-[100%]">
|
||||
|
@ -7,6 +7,7 @@ GOTH // Post
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.post.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
@ -5,6 +5,7 @@ GOTH // SSE <div class="badge badge-accent">DEMO</div>
|
||||
{{end}}
|
||||
|
||||
{{define "head"}}
|
||||
<link rel="stylesheet" href="/public/css/styles.ssedemo.css" />
|
||||
{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
|
1
public/css/styles.blog.css
vendored
Normal file
1
public/css/styles.blog.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/css/styles.css
vendored
1
public/css/styles.css
vendored
File diff suppressed because one or more lines are too long
1
public/css/styles.home.css
vendored
Normal file
1
public/css/styles.home.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/css/styles.post.css
vendored
Normal file
1
public/css/styles.post.css
vendored
Normal file
File diff suppressed because one or more lines are too long
1
public/css/styles.ssedemo.css
vendored
Normal file
1
public/css/styles.ssedemo.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -49,5 +49,37 @@ fi
|
||||
|
||||
echo $BINARY
|
||||
|
||||
# Run the binary
|
||||
$BINARY build -i ./base.css -o ../public/css/styles.css --minify
|
||||
# Infer pages from .html files in the pages directory
|
||||
PAGES=$(ls ../pages/templates/*.html | xargs -n 1 basename | cut -d. -f1)
|
||||
|
||||
# Run the binary for each page
|
||||
for PAGE in $PAGES; do
|
||||
(
|
||||
# Detect which partials are being used in this page
|
||||
PARTIALS=$(grep -o -E '{{template "[^"]+' ../pages/templates/${PAGE}.html | cut -d'"' -f2 | xargs -I{} echo \"../pages/templates/partials/{}.html\")
|
||||
|
||||
# Generate an array of partials and join them with commas
|
||||
PARTIALS_ARRAY=$(echo $PARTIALS | tr ' ' ',')
|
||||
|
||||
# Always include the "header" partial and any other partials that are always used
|
||||
PARTIALS_ARRAY=\"../pages/templates/partials/header.html\",\"../pages/templates/partials/global.html\",$PARTIALS_ARRAY
|
||||
|
||||
# Generate Tailwind config for this page
|
||||
echo "module.exports = {
|
||||
content: [\"../pages/templates/${PAGE}.html\", \"../pages/templates/layouts/*.html\", $PARTIALS_ARRAY],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
daisyui: {
|
||||
themes: [\"night\"],
|
||||
},
|
||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||
}" > tailwind.config.${PAGE}.js
|
||||
|
||||
# Run the binary with the generated config
|
||||
$BINARY build -i ./base.css -c tailwind.config.${PAGE}.js -o ../public/css/styles.${PAGE}.css --minify
|
||||
) &
|
||||
done
|
||||
|
||||
# Wait for all background processes to finish
|
||||
wait
|
12
stylegen/tailwind.config.js
vendored
12
stylegen/tailwind.config.js
vendored
@ -1,12 +0,0 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["../pages/**/*.{html,go}"],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
daisyui: {
|
||||
themes: ["night"],
|
||||
},
|
||||
plugins: [require('daisyui'), require('@tailwindcss/typography')],
|
||||
}
|
||||
|
Reference in New Issue
Block a user