mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
variant: remove unnecessary themeVariantModifier option #831
This commit is contained in:
parent
bd40625c21
commit
ca0db4d815
6 changed files with 12 additions and 29 deletions
|
@ -1,2 +1,2 @@
|
|||
@import "{{ printf "%s-%s%s.css" .prefix .light .suffix }}" 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 .light }}" screen and (prefers-color-scheme: light);
|
||||
@import "{{ printf "%s-%s.css" .prefix .dark }}" screen and (prefers-color-scheme: dark);
|
||||
|
|
|
@ -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 }}";
|
||||
|
||||
#R-sidebar {
|
||||
|
|
|
@ -75,17 +75,6 @@ themeVariant = [
|
|||
{ 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
|
||||
# These options are defining general, non visual behavior.
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{{- $page := . }}
|
||||
{{- $mod := "" }}
|
||||
{{- $autores := resources.Get "css/auto.css" }}
|
||||
{{- $printres := resources.Get "css/format-print.css" }}
|
||||
{{- $nonautothemevariants := slice }}
|
||||
|
@ -54,10 +53,10 @@ Auto run:
|
|||
{{- $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 }}
|
||||
{{- $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 }} -->
|
||||
{{- $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 }} -->
|
||||
{{- end }}
|
||||
{{- $themevariants = $themevariants | append $themevariant }}
|
||||
|
@ -86,7 +85,7 @@ Non-auto run:
|
|||
{{- range $tempthemevariant := $tempthemevariants }}
|
||||
{{- $themevariant := $tempthemevariant }}
|
||||
{{- 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) }}
|
||||
{{- 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 }}
|
||||
|
@ -96,7 +95,7 @@ Non-auto run:
|
|||
{{- $themevariants = $themevariants | append $themevariant }}
|
||||
{{- 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 }} -->
|
||||
|
||||
{{- return collections.Where $themevariants "config" true }}
|
||||
|
@ -104,22 +103,20 @@ Non-auto run:
|
|||
{{- define "partials/get-theme-details.html" }}
|
||||
{{- $themevariant := .themevariant }}
|
||||
{{- $identifier := .identifier }}
|
||||
{{- $mod := .mod }}
|
||||
{{- $themecontent := "" }}
|
||||
{{- with resources.Get (printf "css/theme-%s.css" $identifier) }}
|
||||
{{- $themecontent = .Content }}
|
||||
{{- 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 }}
|
||||
{{- end }}
|
||||
{{- replaceRE (printf `([ \t]*@import\s+[^$]*?theme-[^.]*?)(?:%s)?(\.css)` (replace $mod "." "\\.")) (printf "${1}%s${2}" $mod) $themecontent }}
|
||||
{{- $chroma := "" }}
|
||||
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?chroma-([^.]*?)\.css` $themecontent }}
|
||||
{{- $chroma = index . 1 }}
|
||||
{{- errorf "\"theme-%s.css\": UNSUPPORTED use of @import for chroma stylesheet, instead use '--CODE-theme: %s;'" $identifier $chroma }}
|
||||
{{- end }}
|
||||
{{- range findRESubmatch (printf `[ \t]*@import\s+[^$]*?theme-([^.]*?)%s\.css` (replace $mod "." "\\.")) $themecontent }}
|
||||
{{- range findRESubmatch `[ \t]*@import\s+[^$]*?theme-([^.]*?)\.css` $themecontent }}
|
||||
{{- $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 }}
|
||||
{{- end }}
|
||||
{{- 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 }}
|
||||
{{- end }}
|
||||
{{- $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 }} -->
|
||||
{{- return $themevariant }}
|
||||
{{- end }}
|
|
@ -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/theme.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
|
||||
{{- $themevariants := partialCached "get-theme-variants.hugo" . }}
|
||||
{{- $themevariantmodifier := .Site.Params.themeVariantModifier | default "" }}
|
||||
{{- 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">
|
||||
{{- end }}
|
||||
<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 }};
|
||||
{{- end }}
|
||||
{{ "// variant stuff" | safeJS }}
|
||||
window.relearn.themeVariantModifier='{{ $themevariantmodifier }}';
|
||||
{{- $quotedthemevariants := slice }}
|
||||
{{- range $themevariants }}
|
||||
{{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .identifier) }}
|
||||
|
|
|
@ -60,8 +60,7 @@ var variants = {
|
|||
},
|
||||
|
||||
generateVariantPath: function( variant, old_path ){
|
||||
var mod = window.relearn.themeVariantModifier.replace( '.', '\\.' );
|
||||
var new_path = old_path.replace( new RegExp(`^(.*\/theme-).*?(${mod}\.css.*)$`), '$1' + variant + '$2' );
|
||||
var new_path = old_path.replace( new RegExp(`^(.*\/theme-).*?(\.css.*)$`), '$1' + variant + '$2' );
|
||||
return new_path;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue