Skip to content

Commit

Permalink
variant: add referenced but not configured variants #679
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Nov 26, 2023
1 parent 1119b3f commit 87df35a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions layouts/partials/get-theme-variants.hugo
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
{{- $printres := resources.Get "css/format-print.css" }}

{{- /*
First run:
Config run:
- convert from old forms to slice of dicts
- convert auto property to slice
- add name property
*/}}
{{- $refthemevariants := slice | append "relearn-light" | append "relearn-dark" }}
{{- $tempthemevariants := slice | append (.Site.Params.themeVariant | default "auto" ) }}
{{- $themevariants := slice }}
{{- range $tempthemevariant := $tempthemevariants }}
Expand All @@ -20,12 +21,25 @@ First run:
{{- end }}
{{- if eq $themevariant.identifier "auto" }}
{{- $themevariant = collections.Merge $themevariant (dict "auto" ($themevariant.auto | default slice)) }}
{{- $refthemevariants = $refthemevariants | append $themevariant.auto }}
{{- end }}
{{- $themevariant = collections.Merge $themevariant (dict "config" true) }}
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}

{{- /*
Second run, handle non-auto variants
Ref run:
- add non-configured but referenced variants
*/}}
{{- range $refthemevariant := $refthemevariants }}
{{- if not (index (collections.Where $themevariants "identifier" $refthemevariant) 0) }}
{{- $themevariant := (dict "identifier" $refthemevariant "name" ($refthemevariant | humanize | strings.Title) "config" false) }}
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
{{- end }}

{{- /*
Non-auto run
- fix and regenerate theme css for advanced config mode
- add chroma property from stylesheet
*/}}
Expand Down Expand Up @@ -61,7 +75,7 @@ Second run, handle non-auto variants
{{- end }}

{{- /*
Third run, handle auto variants
Auto run
- fill up auto property
- fill up chroma property
- generate theme and chroma css files from template
Expand Down Expand Up @@ -113,4 +127,4 @@ Third run, handle auto variants
{{- $cssres := $printres | resources.ExecuteAsTemplate "css/format-print.css" (index (collections.Where $themevariants "identifier" "relearn-light") 0) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} -->

{{- return $themevariants }}
{{- return collections.Where $tempthemevariants "config" true }}

0 comments on commit 87df35a

Please sign in to comment.