From 5a87101c708de246230004f7528278da9e5308c9 Mon Sep 17 00:00:00 2001 From: "Jens M. Sauer" Date: Thu, 1 Aug 2024 19:44:14 +0200 Subject: [PATCH] Simplify css and sass aggregation --- layouts/partials/head.html | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index dfb42ee..43e6e2e 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -9,22 +9,33 @@ {{ end }} - {{ if hugo.IsServer }} - {{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "scss/main.scss" . | toCSS (dict "targetPath" "css/main.css" "outputStyle" "compressed" "enableSourceMap" false) }} - - {{ else }} - {{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "scss/main.scss" . | toCSS (dict "targetPath" "css/main.css" "enableSourceMap" false) }} - + {{ $opts := dict "targetPath" "css/main.css" "enableSourceMap" (not hugo.IsProduction) }} + {{ $sass := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "css/main.scss" . | toCSS $opts }} + {{ $css := resources.Match "css/*.css" | resources.Concat "css/bundle.css" }} + {{ with slice $sass $css | resources.Concat "css/main.css" }} + {{ if hugo.IsDevelopment }} + + {{ else }} + {{ with . | minify | fingerprint }} + + {{ end }} + {{ end }} {{ end }} - {{ if hugo.IsServer }} - {{ $noscript := resources.Get "sass/noscript.scss" | resources.ExecuteAsTemplate "noscript.scss" . | toCSS (dict "targetPath" "css/noscript.css" "enableSourceMap" false) }} - - {{ else }} - {{ $noscript := resources.Get "sass/noscript.scss" | resources.ExecuteAsTemplate "noscript.scss" . | toCSS (dict "targetPath" "css/noscript.css" "enableSourceMap" false) }} - - {{end}} - {{ with resources.Match "css/*.css" | resources.Concat "css/bundle.css" | minify | fingerprint }} - + {{ with resources.Get "sass/noscript.scss" }} + {{ $opts := dict "targetPath" "css/noscript.css" "enableSourceMap" (not hugo.IsProduction) }} + {{ with . | resources.ExecuteAsTemplate "scss/main.scss" . | toCSS $opts }} + {{ if hugo.IsDevelopment }} + + {{ else }} + {{ with . | minify | fingerprint }} + + {{ end }} + {{ end }} + {{ end }} {{ end }}