From 49ac91fef980fbe843c4c4184ddaf08933cfd2f6 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 19 May 2019 18:49:41 +0100 Subject: [PATCH] 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 --- assets/sass/academic/_content.scss | 4 -- assets/sass/bootstrap_variables.scss | 1 + layouts/partials/functions/parse_theme.html | 50 +++++++-------------- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/assets/sass/academic/_content.scss b/assets/sass/academic/_content.scss index 6a58e51b..5a2dc7ae 100644 --- a/assets/sass/academic/_content.scss +++ b/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); } diff --git a/assets/sass/bootstrap_variables.scss b/assets/sass/bootstrap_variables.scss index 8dbf7951..f874437e 100644 --- a/assets/sass/bootstrap_variables.scss +++ b/assets/sass/bootstrap_variables.scss @@ -1,2 +1,3 @@ /* Set Bootstrap variables */ $primary: $sta-primary; +$text-muted: rgba(0,0,0,0.54); diff --git a/layouts/partials/functions/parse_theme.html b/layouts/partials/functions/parse_theme.html index 904aff97..270f2374 100644 --- a/layouts/partials/functions/parse_theme.html +++ b/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 -}} - {{ else }} - {{- $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)" -}} + {{ 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)" -}} + {{- $scr.Set "dark_home_section_odd" $theme.home_section_odd -}} + {{- $scr.Set "dark_home_section_even" $theme.home_section_even -}} {{ 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 }}