Simplify css and sass aggregation

This commit is contained in:
Jens M. Sauer 2024-08-01 19:44:14 +02:00
parent 31fdbb7743
commit 5a87101c70

View File

@ -9,22 +9,33 @@
{{ end }}
<!-- CSS -->
{{ if hugo.IsServer }}
{{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "scss/main.scss" . | toCSS (dict "targetPath" "css/main.css" "outputStyle" "compressed" "enableSourceMap" false) }}
<link rel="stylesheet" href="{{ ($style).RelPermalink }}">
{{ else }}
{{ $style := resources.Get "sass/main.scss" | resources.ExecuteAsTemplate "scss/main.scss" . | toCSS (dict "targetPath" "css/main.css" "enableSourceMap" false) }}
<link rel="stylesheet" href="{{ ($style | minify).RelPermalink }}">
{{ $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 }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ else }}
{{ with . | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ end }}
{{ end }}
{{ end }}
{{ if hugo.IsServer }}
{{ $noscript := resources.Get "sass/noscript.scss" | resources.ExecuteAsTemplate "noscript.scss" . | toCSS (dict "targetPath" "css/noscript.css" "enableSourceMap" false) }}
<noscript><link rel="stylesheet" href="{{ ($noscript).RelPermalink }}" /></noscript>
{{ else }}
{{ $noscript := resources.Get "sass/noscript.scss" | resources.ExecuteAsTemplate "noscript.scss" . | toCSS (dict "targetPath" "css/noscript.css" "enableSourceMap" false) }}
<noscript><link rel="stylesheet" href="{{ ($noscript | minify).RelPermalink }}" /></noscript>
{{end}}
{{ with resources.Match "css/*.css" | resources.Concat "css/bundle.css" | minify | fingerprint }}
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
{{ 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 }}
<noscript>
<link rel="stylesheet" href="{{ .RelPermalink }}">
</noscript>
{{ else }}
{{ with . | minify | fingerprint }}
<noscript>
<link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
</noscript>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
</head>