From 6740e7b61df517fde3bc0e4da48fadf7b630954a Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 14 Jul 2023 08:24:30 -0700 Subject: [PATCH] Fix all the CSS resources templates --- layouts/partials/resources/page_css.html | 13 ++++++-- layouts/partials/resources/root_css.html | 24 +++++++------- layouts/partials/resources/section_css.html | 35 +++++++++++++++------ 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/layouts/partials/resources/page_css.html b/layouts/partials/resources/page_css.html index e0470fa..6bd5f43 100644 --- a/layouts/partials/resources/page_css.html +++ b/layouts/partials/resources/page_css.html @@ -1,5 +1,12 @@ -{{ $pageCSS := dict }} +{{ $stylesheets := slice }} {{ with .Resources.Match "*.css" }} - {{ $pageCSS = . | resources.Concat (printf "%s/page.css" $.File.Dir) | fingerprint "md5" }} + {{ range . }} + {{ $stylesheets = $stylesheets | append (. | resources.ExecuteAsTemplate .Name .) }} + {{ end }} + {{ if hugo.IsProduction }} + {{ $stylesheets = slice ($stylesheets + | resources.Concat (printf "%s/page.css" $.File.Dir) + | fingerprint "md5") }} + {{ end }} {{ end }} -{{ return $pageCSS }} +{{ return $stylesheets }} diff --git a/layouts/partials/resources/root_css.html b/layouts/partials/resources/root_css.html index 6f90ef4..f705884 100644 --- a/layouts/partials/resources/root_css.html +++ b/layouts/partials/resources/root_css.html @@ -1,21 +1,21 @@ -{{ $allStylesheets := slice (resources.Get "styles/root.css") - (resources.Get "styles/railroad.css") - (resources.Get "styles/monokai.css") - | append (resources.Match "styles/root/*.css" | sort) }} +{{ $stylesheets := slice (resources.Get "styles/root.css") + (resources.Get "styles/railroad.css") + (resources.Get "styles/monokai.css") + | append (resources.Match "styles/root/*.css" | sort) }} {{ if not hugo.IsProduction }} {{ $allStylesheets = $allStylesheets | append (resources.Get "styles/development.css") }} {{ end }} {{ $rootStylesheets := slice }} +{{ range $stylesheets }} + {{ $rootStylesheets = $rootStylesheets | append (. | resources.ExecuteAsTemplate .Name .) }} +{{ end }} + {{ if hugo.IsProduction }} - {{ $rootStylesheets = $allStylesheets - | resources.ExecuteAsTemplate "styles/root.css" . - | resources.Concat "styles/root.css" - | minify | fingerprint "md5" }} -{{ else }} - {{ range $allStylesheets }} - {{ $rootStylesheets = $rootStylesheets | append (. | resources.ExecuteAsTemplate .Name .) }} - {{ end }} + {{ $rootStylesheets = slice ($rootStylesheets + | resources.Concat "styles/root.css" + | minify + | fingerprint "md5") }} {{ end }} {{ return $rootStylesheets }} diff --git a/layouts/partials/resources/section_css.html b/layouts/partials/resources/section_css.html index 0801efb..e1f4913 100644 --- a/layouts/partials/resources/section_css.html +++ b/layouts/partials/resources/section_css.html @@ -1,11 +1,28 @@ -{{ $sectionCSS := dict }} -{{ $sectionStylesheet := "" }} -{{ if .IsHome }} - {{ $sectionStylesheet = printf "styles/home.css" }} -{{ else }} - {{ $sectionStylesheet = printf "styles/%s.css" .Section }} +{{ $stylesheetName := printf "styles/%s.css" .Section }} + +{{ $stylesheets := slice }} +{{ if gt (len .Section) 0 }} + {{ with resources.Match (printf "styles/%s/*" .Section) }} + {{ $stylesheets = . }} + {{ else }} + {{ with resources.Get $stylesheetName }} + {{ $stylesheets = (slice .) }} + {{ end }} + {{ end }} {{ end }} -{{ with resources.Get $sectionStylesheet }} - {{ $sectionCSS = . | fingerprint "md5" }} + +{{ $sectionStylesheets := slice }} +{{ if $stylesheets }} + {{ range $stylesheets }} + {{ $sectionStylesheets = $sectionStylesheets | append (. | resources.ExecuteAsTemplate .Name .) }} + {{ end }} + + {{ if hugo.IsProduction }} + {{ $sectionStylesheets = slice ($sectionStylesheets + | resources.Concat $stylesheetName + | minify + | fingerprint "md5") }} + {{ end }} {{ end }} -{{ return $sectionCSS }} + +{{ return $sectionStylesheets }}