parse_theme.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. {{- $scr := .Scratch -}}
  2. {{/* Get name of site's Theme. Precedence: Params.toml > Default (Minimal) */}}
  3. {{- $theme_index := (site.Params.theme | lower | replaceRE "\\s" "_") | default "minimal" -}}
  4. {{/* Get name of site's Font Set. Precedence: Params.toml > Theme > Default (Minimal) */}}
  5. {{- $font_index := (site.Params.font | lower | replaceRE "\\s" "_") | default ((index site.Data.themes $theme_index).font | lower | replaceRE "\\s" "_") | default $theme_index -}}
  6. {{- $font_index := cond (isset site.Data.fonts $font_index) $font_index "minimal" -}}
  7. {{/* Get Font Size. */}}
  8. {{- $font_size := lower site.Params.font_size | default "l" -}}
  9. {{- $font_sizes := dict "xs" 14 "s" 16 "m" 18 "l" 21 "xl" 23 -}}
  10. {{- $font_size_numeric := (index $font_sizes $font_size) | default (index $font_sizes "l") -}}
  11. {{- $scr.Set "font_size" $font_size_numeric -}}
  12. {{- $scr.Set "font_size_small" (mul 0.77 $font_size_numeric) -}}
  13. {{/* Load Font Set. */}}
  14. {{- $font := index site.Data.fonts $font_index -}}
  15. {{- $scr.Set "google_fonts" $font.google_fonts -}}
  16. {{- $scr.Set "body_font" $font.body_font -}}
  17. {{- $scr.Set "heading_font" $font.heading_font -}}
  18. {{- $scr.Set "nav_font" $font.nav_font -}}
  19. {{- $scr.Set "mono_font" $font.mono_font -}}
  20. {{/* Load Theme. */}}
  21. {{ $theme := index site.Data.themes $theme_index }}
  22. {{/* Legacy support for `light` as boolean rather than map. */}}
  23. {{ $light_is_map := reflect.IsMap "light" }}
  24. {{ $light_theme := dict }}
  25. {{ if $light_is_map }}
  26. {{ $scr.Set "light" ($theme.is_light | default true) }}
  27. {{ $light_theme = $theme.light }}
  28. {{ else }}
  29. {{ $scr.Set "light" ($theme.light | default true) }}
  30. {{ end }}
  31. {{ if ($scr.Get "light") }}
  32. {{- $scr.Set "background" ($theme.background | default "rgb(255, 255, 255)") -}}
  33. {{- $scr.Set "dark_background" ($theme.dark.background | default "hsla(231, 15%, 16%, 1)") -}}
  34. {{- $scr.Set "home_section_odd" ($theme.home_section_odd | default "rgb(255, 255, 255)") -}}
  35. {{- $scr.Set "home_section_even" ($theme.home_section_even | default "rgb(247, 247, 247)") -}}
  36. {{- $scr.Set "dark_home_section_odd" ($theme.dark.home_section_odd | default "hsla(231, 15%, 18%, 1)") -}}
  37. {{- $scr.Set "dark_home_section_even" ($theme.dark.home_section_even | default "hsla(231, 15%, 16%, 1)") -}}
  38. {{ else }}
  39. {{- $scr.Set "background" ($light_theme.background | default "rgb(255, 255, 255)") -}}
  40. {{- $scr.Set "dark_background" ($theme.background | default "rgb(40, 42, 54)") -}}
  41. {{- $scr.Set "home_section_odd" ($light_theme.home_section_odd | default "rgb(255, 255, 255)") -}}
  42. {{- $scr.Set "home_section_even" ($light_theme.home_section_even | default "rgb(247, 247, 247)") -}}
  43. {{- $scr.Set "dark_home_section_odd" ($theme.home_section_odd | default "hsla(231, 15%, 18%, 1)") -}}
  44. {{- $scr.Set "dark_home_section_even" ($theme.home_section_even | default "hsla(231, 15%, 16%, 1)") -}}
  45. {{ end }}
  46. {{- $scr.Set "link" ($theme.link | default $theme.primary) -}}
  47. {{- $scr.Set "link_hover" ($theme.link_hover | default $theme.primary) -}}
  48. {{- $scr.Set "dark_link" ($theme.dark.link | default $theme.primary) -}}
  49. {{- $scr.Set "dark_link_hover" ($theme.dark.link_hover | default $theme.primary) -}}
  50. {{- $scr.Set "primary" $theme.primary -}}
  51. {{- $scr.Set "menu_primary" $theme.menu_primary -}}
  52. {{- $scr.Set "menu_text" $theme.menu_text -}}
  53. {{- $scr.Set "menu_text_active" $theme.menu_text_active -}}
  54. {{- $scr.Set "menu_title" $theme.menu_title -}}
  55. {{- $scr.Set "dark_menu_primary" ($theme.dark.menu_primary | default "rgb(40, 42, 54)") -}}
  56. {{- $scr.Set "dark_menu_text" ($theme.dark.menu_text | default "white") -}}
  57. {{- $scr.Set "dark_menu_text_active" ($theme.dark.menu_text_active | default "rgba(255, 255, 255, 0.8)") -}}
  58. {{- $scr.Set "dark_menu_title" ($theme.dark.menu_title | default "white") -}}