variant: remove unnecessary themeVariantModifier option #831

This commit is contained in:
Sören Weber 2024-04-19 00:03:45 +02:00
parent bd40625c21
commit ca0db4d815
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
6 changed files with 12 additions and 29 deletions

View file

@ -1,2 +1,2 @@
@import "{{ printf "%s-%s%s.css" .prefix .light .suffix }}" screen and (prefers-color-scheme: light); @import "{{ printf "%s-%s.css" .prefix .light }}" screen and (prefers-color-scheme: light);
@import "{{ printf "%s-%s%s.css" .prefix .dark .suffix }}" screen and (prefers-color-scheme: dark); @import "{{ printf "%s-%s.css" .prefix .dark }}" screen and (prefers-color-scheme: dark);

View file

@ -1,4 +1,4 @@
@import "{{ printf "theme-%s%s.css" .themevariant.identifier .mod }}"; @import "{{ printf "theme-%s.css" .themevariant.identifier }}";
@import "{{ printf "chroma-%s.css" .themevariant.chroma }}"; @import "{{ printf "chroma-%s.css" .themevariant.chroma }}";
#R-sidebar { #R-sidebar {

View file

@ -75,17 +75,6 @@ themeVariant = [
{ identifier = "red" } { identifier = "red" }
] ]
# Filename suffix for variant files.
# Default: not set
# The theme modifies the variant stylesheets during build and tries to store
# them with the same file name. In certain installations it was observed, that
# Hugo could not overwrite these files due to permission issues. If you
# experience this, you can first try to set the `--noChmod` option for Hugo.
# If this still doesn't help you can set this option to eg. ".gen". This will
# be used as a suffix for these generated files, causing them to be newly
# created instead of overwriting the existing ones.
themeVariantModifier = ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# General # General
# These options are defining general, non visual behavior. # These options are defining general, non visual behavior.

View file

@ -1,5 +1,4 @@
{{- $page := . }} {{- $page := . }}
{{- $mod := "" }}
{{- $autores := resources.Get "css/auto.css" }} {{- $autores := resources.Get "css/auto.css" }}
{{- $printres := resources.Get "css/format-print.css" }} {{- $printres := resources.Get "css/format-print.css" }}
{{- $nonautothemevariants := slice }} {{- $nonautothemevariants := slice }}
@ -54,10 +53,10 @@ Auto run:
{{- $dark := index $themevariant.auto 1 | default (index $defaultautothemevariants 1) }} {{- $dark := index $themevariant.auto 1 | default (index $defaultautothemevariants 1) }}
{{- $themevariant = collections.Merge $themevariant (dict "auto" (slice | append $light | append $dark)) }} {{- $themevariant = collections.Merge $themevariant (dict "auto" (slice | append $light | append $dark)) }}
{{- $refthemevariants = $refthemevariants | append $themevariant.auto }} {{- $refthemevariants = $refthemevariants | append $themevariant.auto }}
{{- $cssres := $autores | resources.ExecuteAsTemplate (printf "css/theme-%s%s.css" $themevariant.identifier $mod) (dict "prefix" "theme" "suffix" $mod "light" $light "dark" $dark) }} {{- $cssres := $autores | resources.ExecuteAsTemplate (printf "css/theme-%s.css" $themevariant.identifier) (dict "prefix" "theme" "light" $light "dark" $dark) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} --> {{- /* 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) }} {{- $themevariant = collections.Merge $themevariant (dict "chroma" $themevariant.identifier) }}
{{- $cssres = $autores | resources.ExecuteAsTemplate (printf "css/chroma-%s.css" $themevariant.chroma) (dict "prefix" "chroma" "suffix" "" "light" $light "dark" $dark) }} {{- $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 }} --> {{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} -->
{{- end }} {{- end }}
{{- $themevariants = $themevariants | append $themevariant }} {{- $themevariants = $themevariants | append $themevariant }}
@ -86,7 +85,7 @@ Non-auto run:
{{- range $tempthemevariant := $tempthemevariants }} {{- range $tempthemevariant := $tempthemevariants }}
{{- $themevariant := $tempthemevariant }} {{- $themevariant := $tempthemevariant }}
{{- if not (collections.IsSet $themevariant "auto") }} {{- if not (collections.IsSet $themevariant "auto") }}
{{- $themevariant = partial "get-theme-details.html" (dict "themevariant" $themevariant "identifier" $themevariant.identifier "mod" $mod)}} {{- $themevariant = partial "get-theme-details.html" (dict "themevariant" $themevariant "identifier" $themevariant.identifier)}}
{{- $cssres := resources.Get (printf "css/chroma-%s.css" $themevariant.chroma) }} {{- $cssres := resources.Get (printf "css/chroma-%s.css" $themevariant.chroma) }}
{{- if not $cssres }} {{- 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 }} {{- 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 }}
@ -96,7 +95,7 @@ Non-auto run:
{{- $themevariants = $themevariants | append $themevariant }} {{- $themevariants = $themevariants | append $themevariant }}
{{- end }} {{- end }}
{{- $cssres := $printres | resources.ExecuteAsTemplate "css/format-print.css" (dict "themevariant" (index (collections.Where $themevariants "identifier" "relearn-light") 0) "mod" $mod) }} {{- $cssres := $printres | resources.ExecuteAsTemplate "css/format-print.css" (dict "themevariant" (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 }} --> {{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} -->
{{- return collections.Where $themevariants "config" true }} {{- return collections.Where $themevariants "config" true }}
@ -104,22 +103,20 @@ Non-auto run:
{{- define "partials/get-theme-details.html" }} {{- define "partials/get-theme-details.html" }}
{{- $themevariant := .themevariant }} {{- $themevariant := .themevariant }}
{{- $identifier := .identifier }} {{- $identifier := .identifier }}
{{- $mod := .mod }}
{{- $themecontent := "" }} {{- $themecontent := "" }}
{{- with resources.Get (printf "css/theme-%s.css" $identifier) }} {{- with resources.Get (printf "css/theme-%s.css" $identifier) }}
{{- $themecontent = .Content }} {{- $themecontent = .Content }}
{{- else }} {{- else }}
{{- 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 }} {{- 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 }}
{{- end }} {{- end }}
{{- replaceRE (printf `([ \t]*@import\s+[^$]*?theme-[^.]*?)(?:%s)?(\.css)` (replace $mod "." "\\.")) (printf "${1}%s${2}" $mod) $themecontent }}
{{- $chroma := "" }} {{- $chroma := "" }}
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?chroma-([^.]*?)\.css` $themecontent }} {{- range findRESubmatch `[ \t]*@import\s+[^$]*?chroma-([^.]*?)\.css` $themecontent }}
{{- $chroma = index . 1 }} {{- $chroma = index . 1 }}
{{- errorf "\"theme-%s.css\": UNSUPPORTED use of @import for chroma stylesheet, instead use '--CODE-theme: %s;'" $identifier $chroma }} {{- errorf "\"theme-%s.css\": UNSUPPORTED use of @import for chroma stylesheet, instead use '--CODE-theme: %s;'" $identifier $chroma }}
{{- end }} {{- end }}
{{- range findRESubmatch (printf `[ \t]*@import\s+[^$]*?theme-([^.]*?)%s\.css` (replace $mod "." "\\.")) $themecontent }} {{- range findRESubmatch `[ \t]*@import\s+[^$]*?theme-([^.]*?)\.css` $themecontent }}
{{- $subidentifier := index . 1 }} {{- $subidentifier := index . 1 }}
{{- $themevariant = partial "get-theme-details.html" (dict "themevariant" $themevariant "identifier" $subidentifier "mod" $mod) }} {{- $themevariant = partial "get-theme-details.html" (dict "themevariant" $themevariant "identifier" $subidentifier) }}
{{- $chroma = $themevariant.chroma }} {{- $chroma = $themevariant.chroma }}
{{- end }} {{- end }}
{{- range findRESubmatch `[ \t]*--CODE-theme\s*:\s*([^;]*?)\s*;` $themecontent }} {{- range findRESubmatch `[ \t]*--CODE-theme\s*:\s*([^;]*?)\s*;` $themecontent }}
@ -130,7 +127,7 @@ Non-auto run:
{{- $themecontent = replaceRE `(:root\s*\{[ \t]*)(\s*)` (printf "${1}${2}--CODE-theme: %s;${2}" $chroma) $themecontent }} {{- $themecontent = replaceRE `(:root\s*\{[ \t]*)(\s*)` (printf "${1}${2}--CODE-theme: %s;${2}" $chroma) $themecontent }}
{{- end }} {{- end }}
{{- $themevariant = collections.Merge $themevariant (dict "chroma" $chroma) }} {{- $themevariant = collections.Merge $themevariant (dict "chroma" $chroma) }}
{{- $cssres := $themecontent | resources.FromString (printf "css/theme-%s%s.css" $identifier $mod) }} {{- $cssres := $themecontent | resources.FromString (printf "css/theme-%s.css" $identifier) }}
{{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} --> {{- /* the following code causes Hugo to generate our css file - although it is in comments */}}<!-- {{ $cssres.RelPermalink }} -->
{{- return $themevariant }} {{- return $themevariant }}
{{- end }} {{- end }}

View file

@ -14,9 +14,8 @@
<link href="{{"css/fonts.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="{{"css/fonts.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"></noscript> <link href="{{"css/fonts.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" media="print" onload="this.media='all';this.onload=null;"><noscript><link href="{{"css/fonts.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"></noscript>
<link href="{{"css/theme.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{"css/theme.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
{{- $themevariants := partialCached "get-theme-variants.hugo" . }} {{- $themevariants := partialCached "get-theme-variants.hugo" . }}
{{- $themevariantmodifier := .Site.Params.themeVariantModifier | default "" }}
{{- with index $themevariants 0 }} {{- with index $themevariants 0 }}
<link href="{{(printf "css/theme-%s%s.css" .identifier $themevariantmodifier) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" id="R-variant-style"> <link href="{{(printf "css/theme-%s.css" .identifier) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" id="R-variant-style">
<link href="{{(printf "css/chroma-%s.css" .chroma) | safeHTML | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" id="R-variant-chroma-style"> <link href="{{(printf "css/chroma-%s.css" .chroma) | safeHTML | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" id="R-variant-chroma-style">
{{- end }} {{- end }}
<link href="{{"css/variant.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet"> <link href="{{"css/variant.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
@ -39,7 +38,6 @@
window.index_js_url={{ "index.search.js" | relLangURL }}; window.index_js_url={{ "index.search.js" | relLangURL }};
{{- end }} {{- end }}
{{ "// variant stuff" | safeJS }} {{ "// variant stuff" | safeJS }}
window.relearn.themeVariantModifier='{{ $themevariantmodifier }}';
{{- $quotedthemevariants := slice }} {{- $quotedthemevariants := slice }}
{{- range $themevariants }} {{- range $themevariants }}
{{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .identifier) }} {{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .identifier) }}

View file

@ -60,8 +60,7 @@ var variants = {
}, },
generateVariantPath: function( variant, old_path ){ generateVariantPath: function( variant, old_path ){
var mod = window.relearn.themeVariantModifier.replace( '.', '\\.' ); var new_path = old_path.replace( new RegExp(`^(.*\/theme-).*?(\.css.*)$`), '$1' + variant + '$2' );
var new_path = old_path.replace( new RegExp(`^(.*\/theme-).*?(${mod}\.css.*)$`), '$1' + variant + '$2' );
return new_path; return new_path;
}, },