Ver código fonte

refactor: parse_theme

Clean up code, add some defaults, and add error messages when the
specified font or color theme cannot be found.

Refactor `text-muted` color from CSS override to Bootstrap variable.

Close #680
George Cushen 6 anos atrás
pai
commit
49ac91fef9

+ 0 - 4
assets/sass/academic/_content.scss

@@ -120,10 +120,6 @@ article {
   transition: color 0.6s ease;
 }
 
-.text-muted {
-  color: rgba(0,0,0,0.54); /* Override Bootstrap */
-}
-
 .dark .text-muted {
   color: rgba(255,255,255,0.54);
 }

+ 1 - 0
assets/sass/bootstrap_variables.scss

@@ -1,2 +1,3 @@
 /* Set Bootstrap variables */
 $primary: $sta-primary;
+$text-muted: rgba(0,0,0,0.54);

+ 13 - 31
layouts/partials/functions/parse_theme.html

@@ -1,5 +1,4 @@
 {{- $scr := .Scratch -}}
-{{- $site := $scr.Get "site" -}}
 
 {{/* Attempt to load font style specified by user. */}}
 {{- $font_index := site.Params.font | default "default" -}}
@@ -12,6 +11,8 @@
   {{- $scr.Set "mono_font" $font.mono_font -}}
   {{- $scr.Set "font_size" $font.font_size -}}
   {{- $scr.Set "font_size_small" $font.font_size_small -}}
+{{ else }}
+  {{ errorf "The `%s` font theme was not found! Check that the `font` option in `config/_default/params.toml` matches the name of an installed font theme." $font_index }}
 {{ end }}
 
 {{/* Attempt to load color theme specified by user. */}}
@@ -19,47 +20,26 @@
 {{ if isset site.Data.themes $theme_index }}
   {{ $theme := index site.Data.themes $theme_index }}
 
-  {{- $scr.Set "light" $theme.light -}}
-
-  {{ if and $theme.background $theme.light }}
-    {{- $scr.Set "background" $theme.background -}}
-  {{ else }}
-    {{- $scr.Set "background" "#fff" -}}
-  {{ end }}
-
-  {{ if and $theme.background (not $theme.light) }}
-    {{- $scr.Set "dark_background" $theme.background -}}
-  {{ else }}
-    {{- $scr.Set "dark_background" "rgb(40, 42, 54)" -}}
-  {{ end }}
+  {{- $scr.Set "light" ($theme.light | default true) -}}
 
   {{ if $theme.light }}
+    {{- $scr.Set "background" ($theme.background | default "#fff") -}}
+    {{- $scr.Set "dark_background" "rgb(40, 42, 54)" -}}
     {{- $scr.Set "home_section_odd" $theme.home_section_odd -}}
     {{- $scr.Set "home_section_even" $theme.home_section_even -}}
+    {{- $scr.Set "dark_home_section_odd" "hsla(231, 15%, 18%, 1)" -}}
+    {{- $scr.Set "dark_home_section_even" "hsla(231, 15%, 16%, 1)" -}}
   {{ else }}
+    {{- $scr.Set "background" ($theme.background | default "#fff") -}}
+    {{- $scr.Set "dark_background" ($theme.background | default "rgb(40, 42, 54)") -}}
     {{- $scr.Set "home_section_odd" "rgb(255, 255, 255)" -}}
     {{- $scr.Set "home_section_even" "rgb(247, 247, 247)" -}}
-  {{ end }}
-
-  {{ if not $theme.light }}
     {{- $scr.Set "dark_home_section_odd" $theme.home_section_odd -}}
     {{- $scr.Set "dark_home_section_even" $theme.home_section_even -}}
-  {{ else }}
-    {{- $scr.Set "dark_home_section_odd" "hsla(231, 15%, 18%, 1)" -}}
-    {{- $scr.Set "dark_home_section_even" "hsla(231, 15%, 16%, 1)" -}}
   {{ end }}
 
-  {{ if $theme.link }}
-    {{- $scr.Set "link" $theme.link -}}
-  {{ else }}
-    {{- $scr.Set "link" $theme.primary -}}
-  {{ end }}
-
-  {{ if $theme.link_hover }}
-    {{- $scr.Set "link_hover" $theme.link_hover -}}
-  {{ else }}
-    {{- $scr.Set "link_hover" $theme.primary -}}
-  {{ end }}
+  {{- $scr.Set "link" ($theme.link | default $theme.primary) -}}
+  {{- $scr.Set "link_hover" ($theme.link_hover | default $theme.primary) -}}
 
   {{- $scr.Set "primary" $theme.primary -}}
   {{- $scr.Set "primary_light" $theme.primary_light -}}
@@ -70,4 +50,6 @@
   {{- $scr.Set "menu_text_active" $theme.menu_text_active -}}
   {{- $scr.Set "menu_title" $theme.menu_title -}}
 
+{{ else }}
+  {{ errorf "The `%s` color theme was not found! Check that the `color_theme` option in `config/_default/params.toml` matches the name of an installed color theme." $theme_index }}
 {{ end }}