2023-11-25 13:23:58 +00:00
{{- $page := . }}
2024-04-18 22:02:28 +00:00
{{- $nonautothemevariants := slice }}
2024-12-07 23:06:40 +00:00
{{- $formathtmlpre := ":root:not([data-r-output-format='print']):not([data-r-theme-variant='my-custom-variant'])" }}
2024-12-04 20:37:37 +00:00
{{- $formathtml := "" }}
{{- $minify := not hugo .IsServer }}
2024-12-07 23:06:40 +00:00
{{- if and ( isset site .Params "minify" ) ( ne site .Params .minify "" ) }}
2024-12-04 20:37:37 +00:00
{{- $minify = site .Params .minify }}
{{- end }}
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-12-04 20:37:37 +00:00
- remember default variants for auto mode
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 }}
2024-12-07 23:06:40 +00:00
{{- if eq $themevariant .identifier "my-custom-variant" }}
{{- errorf "\"theme-%s.css\": the variant identifier '%s' is reserved for the theme's variant generator, instead rename it to something different" "my-custom-variant" "my-custom-variant" }}
{{- end }}
2023-11-23 00:05:26 +00:00
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
2024-04-18 22:02:28 +00:00
{{- / *
2024-12-04 20:37:37 +00:00
Generator run:
2024-04-18 22:02:28 +00:00
- fill up auto property with defaults
2024-12-04 20:37:37 +00:00
- write variant & chroma CSS string of normal variants and for light and dark of auto variants
2024-04-18 22:02:28 +00:00
*/}}
{{- $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 ) ) }}
2024-12-04 20:37:37 +00:00
{{- $lightthemevariant := partial "get-theme-details.html" ( dict "themevariant" $themevariant "identifier" $light ) }}
{{- $darkthemevariant := partial "get-theme-details.html" ( dict "themevariant" $themevariant "identifier" $dark ) }}
{{- $formathtmlpre = print $formathtmlpre
":not([data-r-theme-variant='" $themevariant.identifier "'])"
}}
{{- $formathtml = print $formathtml
"\n:root:not([data-r-output-format='print'])[data-r-theme-variant='" $themevariant.identifier "'] { "
"\n@media screen and (prefers-color-scheme: light) { "
2024-12-19 22:37:24 +00:00
"\n" $lightthemevariant.themecontent
2024-12-04 20:37:37 +00:00
"\n" $lightthemevariant.chromacontent
"\n}"
"\n@media screen and (prefers-color-scheme: dark) { "
2024-12-19 22:37:24 +00:00
"\n" $darkthemevariant.themecontent
2024-12-04 20:37:37 +00:00
"\n" $darkthemevariant.chromacontent
"\n}"
"\n}"
}}
{{- else }}
{{- $themevariant = partial "get-theme-details.html" ( dict "themevariant" $themevariant "identifier" $themevariant .identifier ) }}
{{- $formathtmlpre = print $formathtmlpre
":not([data-r-theme-variant='" $themevariant.identifier "'])"
}}
{{- $formathtml = print $formathtml
"\n:root:not([data-r-output-format='print'])[data-r-theme-variant='" $themevariant.identifier "'] { "
2024-12-19 22:37:24 +00:00
"\n" $themevariant.themecontent
2024-12-04 20:37:37 +00:00
"\n" $themevariant.chromacontent
"\n}"
}}
2024-04-18 22:02:28 +00:00
{{- end }}
{{- $themevariants = $themevariants | append $themevariant }}
{{- end }}
2023-11-25 13:23:58 +00:00
{{- / *
2024-12-04 20:37:37 +00:00
- Read default stuff
2023-11-26 17:13:30 +00:00
*/}}
2024-12-04 20:37:37 +00:00
{{- $defaultthemevariant := partial "get-theme-details.html" ( dict "themevariant" ( dict ) "identifier" "relearn-light" ) }}
{{- $nucleuscontent := "" }}
{{- with resources .Get "css/nucleus.css" }}
{{- $nucleuscontent = .Content }}
2023-11-26 17:13:30 +00:00
{{- end }}
2024-12-04 20:37:37 +00:00
{{- $fontscontent := "" }}
{{- with resources .Get "css/fonts.css" }}
{{- $fontscontent = .Content }}
2023-11-20 08:39:40 +00:00
{{- end }}
2024-12-04 20:37:37 +00:00
{{- $htmlcontent := "" }}
{{- with resources .Get "css/format-html.css" }}
{{- $htmlcontent = .Content }}
{{- end }}
{{- $printcontent := "" }}
{{- with resources .Get "css/format-print.css" }}
{{- $printcontent = .Content }}
2024-07-03 20:03:44 +00:00
{{- end }}
2024-09-12 05:55:24 +00:00
{{- / *
2024-12-04 20:37:37 +00:00
- Read variables.css and add custom box styles
2024-09-12 05:55:24 +00:00
*/}}
2024-12-04 20:37:37 +00:00
{{- $variablescontent := "" }}
2024-09-12 05:55:24 +00:00
{{- with resources .Get "css/variables.css" }}
2024-12-04 20:37:37 +00:00
{{- $boxcontent := "" }}
2024-09-12 05:55:24 +00:00
{{- range $page .Site .Params .boxStyle }}
{{- $identifier := upper .identifier }}
2024-12-04 20:37:37 +00:00
{{- $boxcontent = print $boxcontent
2024-09-12 05:55:24 +00:00
"\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 }}
2024-12-04 20:37:37 +00:00
{{- $variablescontent = print
":root { "
"\n" .Content
$boxcontent
"\n}"
}}
2024-09-12 05:55:24 +00:00
{{- end }}
2024-07-04 06:23:54 +00:00
2024-12-04 20:37:37 +00:00
{{- / *
- Write theme.css
*/}}
2024-10-03 10:43:53 +00:00
{{- with resources .Get "css/theme.css" }}
2024-12-04 20:37:37 +00:00
{{- $boxcontent := "" }}
2024-09-12 05:55:24 +00:00
{{- range $page .Site .Params .boxStyle }}
{{- $identifier := upper .identifier }}
{{- $identifierl := lower .identifier }}
2024-12-04 20:37:37 +00:00
{{- $boxcontent = print $boxcontent
2024-09-12 05:55:24 +00:00
"\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 }}
2024-12-04 20:37:37 +00:00
{{- $themecontent := print
$variablescontent
"\n\n" $nucleuscontent
"\n" .Content
$boxcontent
"\n" $fontscontent
}}
{{- $cssres := $themecontent | resources .FromString "css/theme.css" }}
{{- if $minify }}
{{- $cssres = $cssres | minify }}
{{- end }}
2024-09-12 05:55:24 +00:00
{{- /* 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
{{- / *
2024-12-04 20:37:37 +00:00
- Write swagger.css
2024-09-12 05:55:24 +00:00
*/}}
2024-12-04 20:37:37 +00:00
{{- with resources .Get "css/swagger.css" }}
{{- $swaggercontent := print
$variablescontent "\n"
.Content "\n"
$fontscontent "\n"
}}
{{- $cssres := $swaggercontent | resources .FromString "css/swagger.css" }}
{{- if $minify }}
{{- $cssres = $cssres | minify }}
{{- end }}
{{- /* 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-12-04 20:37:37 +00:00
{{- / *
- Write format-html.css
*/}}
{{- $htmlcontent = print
"@media screen { "
"\n" $formathtmlpre ","
$formathtml
"\n}"
"\n@media print { "
2024-12-19 22:37:24 +00:00
"\n" $defaultthemevariant.themecontent
2024-12-04 20:37:37 +00:00
"\n" $defaultthemevariant.chromacontent
"\n}"
"\n@media print { "
"\n" $printcontent
"\n}"
"\n" $htmlcontent
}}
{{- $cssres := $htmlcontent | resources .FromString "css/format-html.css" }}
{{- if $minify }}
{{- $cssres = $cssres | minify }}
{{- 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 }} -->
2024-12-04 20:37:37 +00:00
{{- / *
- Write format-print.css
*/}}
{{- $printcontent = print
":root[data-r-output-format='print'] { "
2024-12-19 22:37:24 +00:00
"\n" $defaultthemevariant.themecontent
2024-12-04 20:37:37 +00:00
"\n" $defaultthemevariant.chromacontent
"\n}"
"\n" $printcontent
}}
{{- $cssres := $printcontent | resources .FromString "css/format-print.css" }}
{{- if $minify }}
{{- $cssres = $cssres | minify }}
{{- end }}
2024-09-12 05:55:24 +00:00
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}} <!-- {{ $cssres .RelPermalink }} -->
2024-12-04 20:37:37 +00:00
{{- return $themevariants }}
2023-11-26 19:34:08 +00:00
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-12-19 22:37:24 +00:00
{{- $themecontent = replaceRE `([ \t]*)(:root)` "${1}&${2}" .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-12-04 20:37:37 +00:00
{{- $chromacontent := "" }}
2024-04-18 22:02:28 +00:00
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?chroma-([^.]*?)\.css` $themecontent }}
{{- $chroma = index . 1 }}
2024-09-29 21:54:17 +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/introduction/releasenotes/6/#6-0-0" $identifier $chroma }}
2024-04-18 22:02:28 +00:00
{{- end }}
2024-12-04 20:37:37 +00:00
{{- $tempthemecontent := $themecontent }}
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-12-19 22:01:28 +00:00
{{- $tempthemecontent = replaceRE ( printf `[ \t]*@import\s+[^$]*?theme-%s\.css["']?\s*\)?\s*;?` $subidentifier ) $themevariant .themecontent $tempthemecontent 1 }}
2024-04-18 22:02:28 +00:00
{{- $chroma = $themevariant .chroma }}
2024-12-04 20:37:37 +00:00
{{- $chromacontent = $themevariant .chromacontent }}
2024-04-18 22:02:28 +00:00
{{- end }}
2024-12-19 22:37:24 +00:00
{{- $themecontent = replaceRE `(&\s*)+:root` "&:root" $tempthemecontent }}
2023-11-26 19:34:08 +00:00
{{- range findRESubmatch `[ \t]*--CODE-theme\s*:\s*([^;]*?)\s*;` $themecontent }}
{{- $chroma = index . 1 }}
2024-12-04 20:37:37 +00:00
{{- $cssres := resources .Get ( printf "css/chroma-%s.css" $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\"" $chroma }}
{{- end }}
{{- $chromacontent = $cssres .Content }}
2024-04-18 22:02:28 +00:00
{{- end }}
{{- if not $chroma }}
{{- $chroma = "relearn-light" }}
2024-12-04 20:37:37 +00:00
{{- $cssres := resources .Get ( printf "css/chroma-%s.css" $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\"" $chroma }}
{{- end }}
{{- $chromacontent = $cssres .Content }}
2023-11-26 19:34:08 +00:00
{{- $themecontent = replaceRE `(:root\s*\{[ \t]*)(\s*)` ( printf "${1}${2}--CODE-theme: %s;${2}" $chroma ) $themecontent }}
{{- end }}
2024-12-04 20:37:37 +00:00
{{- $themevariant = collections .Merge $themevariant ( dict "themecontent" $themecontent ) }}
2023-12-03 17:31:44 +00:00
{{- $themevariant = collections .Merge $themevariant ( dict "chroma" $chroma ) }}
2024-12-04 20:37:37 +00:00
{{- $themevariant = collections .Merge $themevariant ( dict "chromacontent" $chromacontent ) }}
2023-12-03 17:31:44 +00:00
{{- return $themevariant }}
2023-11-26 19:34:08 +00:00
{{- end }}