Skip to content

Commit

Permalink
refactor: parse_theme
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gcushen committed May 19, 2019
1 parent efb4f32 commit 49ac91f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
4 changes: 0 additions & 4 deletions assets/sass/academic/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions assets/sass/bootstrap_variables.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* Set Bootstrap variables */
$primary: $sta-primary;
$text-muted: rgba(0,0,0,0.54);
44 changes: 13 additions & 31 deletions layouts/partials/functions/parse_theme.html
Original file line number Diff line number Diff line change
@@ -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" -}}
Expand All @@ -12,54 +11,35 @@
{{- $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. */}}
{{- $theme_index := site.Params.color_theme | default "default" -}}
{{ 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 -}}
Expand All @@ -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 }}

0 comments on commit 49ac91f

Please sign in to comment.