parse_theme.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. {{- $scr := .Scratch -}}
  2. {{/* Get name of site's Color Theme. Precedence: Params.yaml > Default (Minimal) */}}
  3. {{- $theme_day_index := (site.Params.appearance.theme_day | lower | replaceRE "\\s" "_") | default "minimal" -}}
  4. {{- $theme_night_index := (site.Params.appearance.theme_night | lower | replaceRE "\\s" "_") | default "minimal" -}}
  5. {{- if not (index (index site.Data.themes $theme_day_index) "light") -}}
  6. {{- warnf "Theme `%s` not found at `data/themes/%s.toml`" site.Params.appearance.theme_day $theme_day_index -}}
  7. {{- $theme_day_index = "minimal" -}}
  8. {{ end }}
  9. {{- if not (index (index site.Data.themes $theme_night_index) "dark") -}}
  10. {{- warnf "Theme `%s` not found at `data/themes/%s.toml`" site.Params.appearance.theme_night $theme_night_index -}}
  11. {{- $theme_night_index = "minimal" -}}
  12. {{ end }}
  13. {{ $theme_day := index (index site.Data.themes $theme_day_index) "light" }}
  14. {{ $theme_night := index (index site.Data.themes $theme_night_index) "dark" }}
  15. {{/* Legacy support for `light` as boolean rather than map. */}}
  16. {{ $light_is_map := reflect.IsMap $theme_day }}
  17. {{ if not $light_is_map }}
  18. {{ errorf "Upgrade your %s theme pack for v5.5. Convert `light = ...` to `[light]`." $theme_day_index }}
  19. {{ end }}
  20. {{/* Default CSS body class. */}}
  21. {{ if site.Params.appearance.theme_day }}
  22. {{ $scr.Set "light" true }}
  23. {{ else }}
  24. {{ $scr.Set "light" false }}
  25. {{ end }}
  26. {{/* Get name of site's Font Set. Precedence: Params.yaml > Inherit from Color Theme > Default (Minimal) */}}
  27. {{- $font_index := (site.Params.appearance.font | lower | replaceRE "\\s" "_") | default ((index site.Data.themes $theme_day_index).font | lower | replaceRE "\\s" "_") | default $theme_day_index -}}
  28. {{- $font_index := cond (isset site.Data.fonts $font_index) $font_index "minimal" -}}
  29. {{/* Get Font Size. */}}
  30. {{- $font_size := lower site.Params.appearance.font_size | default "l" -}}
  31. {{- $font_sizes := dict "xs" 14 "s" 16 "m" 18 "l" 21 "xl" 23 -}}
  32. {{- $font_size_numeric := (index $font_sizes $font_size) | default (index $font_sizes "l") -}}
  33. {{- $scr.Set "font_size" $font_size_numeric -}}
  34. {{- $scr.Set "font_size_small" (mul 0.77 $font_size_numeric) -}}
  35. {{/* Load Font Set. */}}
  36. {{- $font := index site.Data.fonts $font_index -}}
  37. {{- $scr.Set "google_fonts" $font.google_fonts -}}
  38. {{- $scr.Set "body_font" $font.body_font -}}
  39. {{- $scr.Set "heading_font" $font.heading_font -}}
  40. {{- $scr.Set "nav_font" $font.nav_font -}}
  41. {{- $scr.Set "mono_font" $font.mono_font -}}
  42. {{/* Load Theme. */}}
  43. {{ if site.Params.appearance.theme_day }}
  44. {{- $scr.Set "primary" ($theme_day.primary | default "#1565c0") -}}
  45. {{ else }}
  46. {{- $scr.Set "primary" ($theme_night.primary | default "#1565c0") -}}
  47. {{ end }}
  48. {{- $scr.Set "background" ($theme_day.background | default "rgb(255, 255, 255)") -}}
  49. {{- $scr.Set "home_section_odd" ($theme_day.home_section_odd | default "rgb(255, 255, 255)") -}}
  50. {{- $scr.Set "home_section_even" ($theme_day.home_section_even | default "rgb(247, 247, 247)") -}}
  51. {{- $scr.Set "dark_background" ($theme_night.background | default "hsla(231, 15%, 16%, 1)") -}}
  52. {{- $scr.Set "dark_home_section_odd" ($theme_night.home_section_odd | default "hsla(231, 15%, 18%, 1)") -}}
  53. {{- $scr.Set "dark_home_section_even" ($theme_night.home_section_even | default "hsla(231, 15%, 16%, 1)") -}}
  54. {{- $scr.Set "link" ($theme_day.link | default $theme_day.primary | default ($scr.Get "primary")) -}}
  55. {{- $scr.Set "link_hover" ($theme_day.link_hover | default $theme_day.primary | default ($scr.Get "primary")) -}}
  56. {{- $scr.Set "link_decoration" ($theme_day.link_decoration | default "inherit") -}}
  57. {{- $scr.Set "dark_link" ($theme_night.link | default $theme_night.primary | default ($scr.Get "primary")) -}}
  58. {{- $scr.Set "dark_link_hover" ($theme_night.link_hover | default $theme_night.primary | default ($scr.Get "primary")) -}}
  59. {{- $scr.Set "dark_link_decoration" ($theme_night.link_decoration | default "inherit") -}}
  60. {{- $scr.Set "menu_primary" $theme_day.menu_primary -}}
  61. {{- $scr.Set "menu_text" $theme_day.menu_text -}}
  62. {{- $scr.Set "menu_text_active" $theme_day.menu_text_active -}}
  63. {{- $scr.Set "menu_title" $theme_day.menu_title -}}
  64. {{- $scr.Set "dark_menu_primary" ($theme_night.menu_primary | default "rgb(40, 42, 54)") -}}
  65. {{- $scr.Set "dark_menu_text" ($theme_night.menu_text | default "white") -}}
  66. {{- $scr.Set "dark_menu_text_active" ($theme_night.menu_text_active | default "rgba(255, 255, 255, 0.8)") -}}
  67. {{- $scr.Set "dark_menu_title" ($theme_night.menu_title | default "white") -}}