2023-11-25 13:23:58 +00:00
{{- $page := . }}
{{- $autores := resources .Get "css/auto.css" }}
2024-04-18 22:02:28 +00:00
{{- $nonautothemevariants := slice }}
{{- /* we need relearn-light in every case for the print styles */}}
{{- $refthemevariants := slice | append "relearn-light" }}
2023-11-25 13:23:58 +00:00
{{- / *
2024-04-18 22:02:28 +00:00
Unification run:
2023-11-25 13:23:58 +00:00
- convert from old forms to slice of dicts
2024-04-18 22:02:28 +00:00
- add default name property
2023-11-25 13:23:58 +00:00
- convert auto property to slice
2024-04-18 22:02:28 +00:00
- save non auto variants to later assign them as default for missing auto variants
- mark variants configured by the user
2023-11-25 13:23:58 +00:00
*/}}
2023-11-20 08:39:40 +00:00
{{- $tempthemevariants := slice | append ( .Site .Params .themeVariant | default "auto" ) }}
2023-11-23 00:05:26 +00:00
{{- $themevariants := slice }}
2023-11-20 08:39:40 +00:00
{{- range $tempthemevariant := $tempthemevariants }}
{{- $themevariant := $tempthemevariant }}
{{- if not ( reflect .IsMap $themevariant ) }}
{{- $themevariant = dict "identifier" $tempthemevariant }}
{{- end }}
{{- if not $themevariant .name }}
{{- $themevariant = collections .Merge $themevariant ( dict "name" ( $themevariant .identifier | humanize | strings .Title ) ) }}
{{- end }}
2023-11-23 00:05:26 +00:00
{{- if eq $themevariant .identifier "auto" }}
{{- $themevariant = collections .Merge $themevariant ( dict "auto" ( $themevariant .auto | default slice ) ) }}
2024-04-18 22:02:28 +00:00
{{- end }}
{{- if not ( isset $themevariant "auto" ) }}
{{- $nonautothemevariants = $nonautothemevariants | append $themevariant .identifier }}
2023-11-23 00:05:26 +00:00
{{- end }}
2023-11-26 17:13:30 +00:00
{{- $themevariant = collections .Merge $themevariant ( dict "config" true ) }}
2023-11-23 00:05:26 +00:00
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
2024-04-18 22:02:28 +00:00
{{- / *
Auto run:
- fill up auto property with defaults
- save variants referenced by auto configuration
- write variant CSS file based on auto template
- add chroma property
*/}}
{{- $defaultautothemevariants := slice }}
{{- $defaultautothemevariants = $defaultautothemevariants | append ( index .Site .Params .themeVariantAuto 0 | default ( index $nonautothemevariants 0 ) | default "relearn-light" ) }}
{{- $defaultautothemevariants = $defaultautothemevariants | append ( index .Site .Params .themeVariantAuto 1 | default ( index $nonautothemevariants 1 ) | default "relearn-dark" ) }}
{{- $tempthemevariants = $themevariants }}
{{- $themevariants = slice }}
{{- range $tempthemevariant := $tempthemevariants }}
{{- $themevariant := $tempthemevariant }}
{{- if collections .IsSet $themevariant "auto" }}
{{- $light := index $themevariant .auto 0 | default ( index $defaultautothemevariants 0 ) }}
{{- $dark := index $themevariant .auto 1 | default ( index $defaultautothemevariants 1 ) }}
{{- $themevariant = collections .Merge $themevariant ( dict "auto" ( slice | append $light | append $dark ) ) }}
{{- $refthemevariants = $refthemevariants | append $themevariant .auto }}
2024-04-18 22:03:45 +00:00
{{- $cssres := $autores | resources .ExecuteAsTemplate ( printf "css/theme-%s.css" $themevariant .identifier ) ( dict "prefix" "theme" "light" $light "dark" $dark ) }}
2024-04-18 22:02:28 +00:00
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
{{- $themevariant = collections .Merge $themevariant ( dict "chroma" $themevariant .identifier ) }}
{{- end }}
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
2023-11-25 13:23:58 +00:00
{{- / *
2023-11-26 17:13:30 +00:00
Ref run:
2024-04-18 22:02:28 +00:00
- add variants referenced by auto properties
- add default name property
2023-11-26 17:13:30 +00:00
*/}}
{{- 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 }}
{{- / *
2024-04-18 22:02:28 +00:00
Non-auto run:
- write variant CSS file and all imported variant CSS files
- add chroma property from deepest imported variant
- write chroma CSS file (just the root one because they are not allowed to be nested and the deepest one wins)
2023-11-25 13:23:58 +00:00
*/}}
{{- $tempthemevariants = $themevariants }}
{{- $themevariants = slice }}
{{- range $tempthemevariant := $tempthemevariants }}
{{- $themevariant := $tempthemevariant }}
{{- if not ( collections .IsSet $themevariant "auto" ) }}
2024-04-18 22:03:45 +00:00
{{- $themevariant = partial "get-theme-details.html" ( dict "themevariant" $themevariant "identifier" $themevariant .identifier ) }}
2024-04-18 22:02:28 +00:00
{{- $cssres := resources .Get ( printf "css/chroma-%s.css" $themevariant .chroma ) }}
{{- if not $cssres }}
{{- errorf "\"chroma-%s.css\": file not found in \"assets/css\"; if you are migrating from a theme version older thant 6.0.0, you have to move it over from \"static/css\"" $themevariant .chroma }}
2023-11-23 00:05:26 +00:00
{{- end }}
2023-11-25 13:23:58 +00:00
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
2023-11-23 00:05:26 +00:00
{{- end }}
2023-11-20 08:39:40 +00:00
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
2023-11-25 13:23:58 +00:00
2024-07-03 20:03:44 +00:00
{{- / *
Chroma auto run:
- write chroma CSS file based on auto template
*/}}
{{- range $tempthemevariant := $themevariants }}
{{- $themevariant := $tempthemevariant }}
{{- if collections .IsSet $themevariant "auto" }}
{{- $lighttheme := index $themevariant .auto 0 | default ( index $defaultautothemevariants 0 ) }}
{{- $darktheme := index $themevariant .auto 1 | default ( index $defaultautothemevariants 1 ) }}
{{- $light := ( index ( collections .Where $themevariants "identifier" $lighttheme ) 0 ) .chroma }}
{{- $dark := ( index ( collections .Where $themevariants "identifier" $darktheme ) 0 ) .chroma }}
{{- $cssres := $autores | resources .ExecuteAsTemplate ( printf "css/chroma-%s.css" $themevariant .chroma ) ( dict "prefix" "chroma" "light" $light "dark" $dark ) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
{{- end }}
{{- end }}
2024-09-12 05:55:24 +00:00
{{- / *
- Add box styles to variables and variants
*/}}
{{- with resources .Get "css/variables.css" }}
{{- $variablescontent := print ":root {\n" .Content }}
{{- range $page .Site .Params .boxStyle }}
{{- $identifier := upper .identifier }}
{{- $variablescontent = print $variablescontent "\n"
"\n --INTERNAL-BOX-" $identifier "-color: var(--BOX-" $identifier "-color, " .color ");"
"\n --INTERNAL-BOX-" $identifier "-TEXT-color: var(--BOX-" $identifier "-TEXT-color, var(--INTERNAL-BOX-TEXT-color));"
}}
{{- end }}
{{- $variablescontent = print $variablescontent "\n}" }}
{{- $cssres := $variablescontent | resources .FromString "css/variables.css" }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
{{- end }}
2024-07-04 06:23:54 +00:00
2024-09-12 05:55:24 +00:00
{{- with resources .Get "css/variant.css" }}
2024-08-29 10:28:34 +00:00
{{- $assetBusting := partialCached "relearn/assetbusting.hugo" . }}
2024-09-12 05:55:24 +00:00
{{- $variantcontent := print `@import "variables.css` $assetBusting `";` "\n\n" .Content }}
{{- range $page .Site .Params .boxStyle }}
{{- $identifier := upper .identifier }}
{{- $identifierl := lower .identifier }}
{{- $variantcontent = print $variantcontent
"\n.cstyle." $identifierl " { "
"\n --VARIABLE-BOX-color: var(--INTERNAL-BOX-" $identifier "-color);"
"\n --VARIABLE-BOX-TEXT-color: var(--INTERNAL-BOX-" $identifier "-TEXT-color);"
"\n}\n"
}}
{{- end }}
{{- $cssres := $variantcontent | resources .FromString "css/variant.css" }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
{{- end }}
2024-07-04 06:23:54 +00:00
2024-09-12 05:55:24 +00:00
{{- / *
- The ugly rest
*/}}
2024-07-04 06:23:54 +00:00
{{- $printres := resources .Get "css/print.css" }}
{{- $cssres := $printres | resources .ExecuteAsTemplate "css/print.css" ( dict ) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
{{- $formatprintres := resources .Get "css/format-print.css" }}
{{- $cssres := $formatprintres | resources .ExecuteAsTemplate "css/format-print.css" ( dict "themevariant" ( index ( collections .Where $themevariants "identifier" "relearn-light" ) 0 ) ) }}
2023-11-25 13:23:58 +00:00
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
2024-09-12 05:55:24 +00:00
{{- $swaggerres := resources .Get "css/swagger.css" }}
{{- $cssres := $swaggerres | resources .ExecuteAsTemplate "css/swagger.css" ( dict ) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
2023-11-26 19:34:08 +00:00
{{- return collections .Where $themevariants "config" true }}
2024-04-18 22:02:28 +00:00
{{- define "partials/get-theme-details.html" }}
2023-12-03 17:31:44 +00:00
{{- $themevariant := .themevariant }}
2023-12-03 14:22:32 +00:00
{{- $identifier := .identifier }}
2023-11-26 19:34:08 +00:00
{{- $themecontent := "" }}
{{- with resources .Get ( printf "css/theme-%s.css" $identifier ) }}
2024-04-18 22:02:28 +00:00
{{- $themecontent = .Content }}
2023-11-26 19:34:08 +00:00
{{- else }}
2024-04-18 22:02:28 +00:00
{{- errorf "\"theme-%s.css\": file not found in \"assets/css\"; if you are migrating from a theme version older thant 6.0.0, you have to move it over from \"static/css\"" $identifier }}
2023-11-26 19:34:08 +00:00
{{- end }}
{{- $chroma := "" }}
2024-04-18 22:02:28 +00:00
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?chroma-([^.]*?)\.css` $themecontent }}
{{- $chroma = index . 1 }}
2024-04-24 20:42:49 +00:00
{{- errorf "\"theme-%s.css\": UNSUPPORTED use of @import for chroma stylesheet, instead use '--CODE-theme: %s;'; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#600" $identifier $chroma }}
2024-04-18 22:02:28 +00:00
{{- end }}
2024-04-18 22:03:45 +00:00
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?theme-([^.]*?)\.css` $themecontent }}
2024-04-18 22:02:28 +00:00
{{- $subidentifier := index . 1 }}
2024-04-18 22:03:45 +00:00
{{- $themevariant = partial "get-theme-details.html" ( dict "themevariant" $themevariant "identifier" $subidentifier ) }}
2024-04-18 22:02:28 +00:00
{{- $chroma = $themevariant .chroma }}
{{- end }}
2023-11-26 19:34:08 +00:00
{{- range findRESubmatch `[ \t]*--CODE-theme\s*:\s*([^;]*?)\s*;` $themecontent }}
{{- $chroma = index . 1 }}
2024-04-18 22:02:28 +00:00
{{- end }}
{{- if not $chroma }}
{{- $chroma = "relearn-light" }}
2023-11-26 19:34:08 +00:00
{{- $themecontent = replaceRE `(:root\s*\{[ \t]*)(\s*)` ( printf "${1}${2}--CODE-theme: %s;${2}" $chroma ) $themecontent }}
{{- end }}
2023-12-03 17:31:44 +00:00
{{- $themevariant = collections .Merge $themevariant ( dict "chroma" $chroma ) }}
2024-04-18 22:03:45 +00:00
{{- $cssres := $themecontent | resources .FromString ( printf "css/theme-%s.css" $identifier ) }}
2023-12-04 17:03:53 +00:00
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
2023-12-03 17:31:44 +00:00
{{- return $themevariant }}
2023-11-26 19:34:08 +00:00
{{- end }}