Skip to content

Commit

Permalink
fix: fallback unsupported color value to auto
Browse files Browse the repository at this point in the history
Fixed #659
  • Loading branch information
razonyang committed Aug 16, 2022
1 parent 16a2095 commit d31e780
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion exampleSite/config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ palette = "purple" # Default palette. Optional. You'll need to clear the browser
# palettes = ["blue", "blue gray", "purple"] # Available palettes. Default to ALL.
# palettes = [] # Disable palette switcher.

# color = "dark" # light, dark or dynamic. Default to dynamic.
# color = "dark" # light, dark or auto. Default to auto.

# fullWidth = true # Full width.
# fixedHeader = false # Turn on/off fixed header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The site parameters are located in `config/_default/params.toml` by default.
| `brand` | String | - | Brand text.
| `description` | String | - | Site description.
| `keywords` | String | - | Site keywords.
| `color` | String | - | Color mode, `light`, `dark` or dynamic. Default to dynamic.
| `color` | String | - | Color mode, `light`, `dark` or `auto`. Default to `auto`.
| `palette` | String | - | Default palette. This will take effect after clearing the Cookie.
| `palettes` | Array | **ALL** | Available palettes. You can disable it by setting it to empty `[]`.
| `featuredPostCount` | Integer/Boolean | `5` | The number of featured posts shown in sidebar. Turn off by setting it to `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ authors = ["RazonYang"]
| `brand` | String | - | Brand
| `description` | String | - | 站点描述
| `keywords` | String | - | 站点关键词
| `color` | String | - | 颜色风格, `light``dark` 或者 dynamic(默认)。
| `color` | String | - | 颜色风格, `light``dark` 或者 `auto`(默认)。
| `palette` | String | - | 默认配色,清理 Cookie 后生效。
| `palettes` | Array | **ALL** | 可选配色,如需禁用此选项,可将其设为空值 `[]`
| `featuredPostCount` | Integer/Boolean | `5` | 精选文章数,`false` 则隐藏。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ authors = ["RazonYang"]
| `brand` | String | - | Brand
| `description` | String | - | 站點描述
| `keywords` | String | - | 站點關鍵詞
| `color` | String | - | 顏色風格, `light``dark` 或者 dynamic(默認)。
| `color` | String | - | 顏色風格, `light``dark` 或者 `auto`(默認)。
| `palette` | String | - | 默認配色,清理 Cookie 後生效。
| `palettes` | Array | **ALL** | 可選配色,如需禁用此選項,可將其設為空值 `[]`
| `featuredPostCount` | Integer/Boolean | `5` | 精選文章數,`false` 則隱藏。
Expand Down
3 changes: 3 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<!doctype html>
{{- $color := default "auto" $.Site.Params.color }}
{{- if not (in (slice "light" "dark" "auto") $color) }}
{{- $color = "auto" }}
{{- end }}
<html class="position-relative" itemscope itemtype="http:https://schema.org/WebPage" lang="{{ .Lang }}" data-theme="{{ $color }}"
{{- with $.Site.Language.LanguageDirection }} dir="{{ . }}"{{ end }}
{{- with $.Site.Params.palette }} data-palette="{{ replace . " " "-" }}"{{ end }}>
Expand Down
3 changes: 3 additions & 0 deletions layouts/partials/header/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<li class="nav-item dropdown col-6 col-lg-auto">
{{- $modes := dict "light" (dict "icon" "sun") "dark" (dict "icon" "moon") "auto" (dict "icon" "adjust") }}
{{- $mode := default "auto" $.Site.Params.color }}
{{- if not (in (slice "light" "dark" "auto") $mode) }}
{{- $mode = "auto" }}
{{- end }}
<a class="nav-link px-0 py-2 px-lg-1" href="#" id="modeDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="mode-icon fas fa-fw fa-{{ (index $modes $mode ).icon }}" id="modeIcon"></i>
<span class="d-lg-none">{{ i18n "mode" }}</span>
Expand Down

0 comments on commit d31e780

Please sign in to comment.