mirror of https://github.com/jpanther/congo.git
🚧 Add config parameters for dark appearance
parent
9d42b7be2b
commit
81824a1a00
|
@ -6,6 +6,8 @@
|
||||||
# https://jpanther.github.io/congo/docs/configuration/#theme-parameters
|
# https://jpanther.github.io/congo/docs/configuration/#theme-parameters
|
||||||
|
|
||||||
colorScheme = "congo"
|
colorScheme = "congo"
|
||||||
|
# darkMode = "auto"
|
||||||
|
# darkToggle = false
|
||||||
# logo = "img/logo.jpg"
|
# logo = "img/logo.jpg"
|
||||||
# description = "My awesome website"
|
# description = "My awesome website"
|
||||||
# mainSections = ["section1", "section2"]
|
# mainSections = ["section1", "section2"]
|
||||||
|
|
|
@ -56,6 +56,8 @@ Many of the article defaults here can be overridden on a per article basis by sp
|
||||||
|Name|Type|Default|Description|
|
|Name|Type|Default|Description|
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|`colorScheme`|string|`"congo"`|The theme colour scheme to use. Valid values are `congo` (default), `avocado`, `ocean`, `fire` and `slate`. Refer to the [Colour Schemes]({{< ref "getting-started#colour-schemes" >}}) section for more details.|
|
|`colorScheme`|string|`"congo"`|The theme colour scheme to use. Valid values are `congo` (default), `avocado`, `ocean`, `fire` and `slate`. Refer to the [Colour Schemes]({{< ref "getting-started#colour-schemes" >}}) section for more details.|
|
||||||
|
|`darkMode`|boolean or string|`"auto"`|The preferred theme appearance for dark mode. Set to `true` to force dark appearance or `false` to force light appearance. Using `"auto"` will defer to the user's operating system preference.|
|
||||||
|
|`darkToggle`|boolean|`false`|When `darkMode` is set to `"auto"`, this parameter determines whether or not to show the appearance toggle in the site footer. The browser's local storage is used to persist the user's preference.|
|
||||||
|`logo`|string|_Not set_|The relative path to the site logo file within the `assets/` folder. The logo file should be provided at 2x resolution and supports any image dimensions.|
|
|`logo`|string|_Not set_|The relative path to the site logo file within the `assets/` folder. The logo file should be provided at 2x resolution and supports any image dimensions.|
|
||||||
|`description`|string|_Not set_|The description of the website for metadata purposes.|
|
|`description`|string|_Not set_|The description of the website for metadata purposes.|
|
||||||
|`mainSections`|array of strings|_Not set_|The sections that should be displayed in the recent articles list. If not provided the section with the greatest number of articles is used.|
|
|`mainSections`|array of strings|_Not set_|The sections that should be displayed in the recent articles list. If not provided the section with the greatest number of articles is used.|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ with .Site.LanguageCode }}{{ . }}{{ else }}en{{ end }}">
|
<html
|
||||||
|
lang="{{ with .Site.LanguageCode }}{{ . }}{{ else }}en{{ end }}"
|
||||||
|
{{ if .Site.Params.darkMode | default false }}class="dark"{{ end }}
|
||||||
|
>
|
||||||
{{- partial "head.html" . -}}
|
{{- partial "head.html" . -}}
|
||||||
<body
|
<body
|
||||||
class="flex flex-col h-screen px-6 m-auto text-lg leading-7 bg-neutral text-neutral-900 sm:px-14 md:px-24 lg:px-32 dark:bg-neutral-800 dark:text-neutral max-w-7xl"
|
class="flex flex-col h-screen px-6 m-auto text-lg leading-7 bg-neutral text-neutral-900 sm:px-14 md:px-24 lg:px-32 dark:bg-neutral-800 dark:text-neutral max-w-7xl"
|
||||||
|
|
|
@ -39,26 +39,29 @@
|
||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm cursor-pointer text-neutral-400 dark:text-neutral-500">
|
{{/* Dark mode toggle */}}
|
||||||
<button
|
{{ if and (.Site.Params.darkToggle | default false) (eq (.Site.Params.darkMode | default "auto") "auto") }}
|
||||||
id="dark-toggle"
|
<div class="text-sm cursor-pointer text-neutral-400 dark:text-neutral-500">
|
||||||
onclick="setPreferredScheme('dark');"
|
<button
|
||||||
oncontextmenu="setPreferredScheme('default'); return false;"
|
id="dark-toggle"
|
||||||
class="inline px-2 py-1 border rounded-md border-neutral-200 dark:hidden hover:text-primary-500 hover:border-primary-400"
|
onclick="setPreferredAppearance('dark');"
|
||||||
title="Switch to dark mode"
|
oncontextmenu="setPreferredAppearance('default'); return false;"
|
||||||
>
|
class="inline px-2 py-1 border rounded-md border-neutral-200 dark:hidden hover:text-primary-500 hover:border-primary-400"
|
||||||
{{ partial "icon.html" "moon" }}
|
title="Switch to dark appearance"
|
||||||
</button>
|
>
|
||||||
<button
|
{{ partial "icon.html" "moon" }}
|
||||||
id="light-toggle"
|
</button>
|
||||||
onclick="setPreferredScheme('light');"
|
<button
|
||||||
oncontextmenu="setPreferredScheme('default'); return false;"
|
id="light-toggle"
|
||||||
class="hidden px-2 py-1 border rounded-md cursor-pointer dark:inline border-neutral-700 hover:text-primary-400 hover:border-primary-500"
|
onclick="setPreferredAppearance('light');"
|
||||||
title="Switch to light mode"
|
oncontextmenu="setPreferredAppearance('default'); return false;"
|
||||||
>
|
class="hidden px-2 py-1 border rounded-md cursor-pointer dark:inline border-neutral-700 hover:text-primary-400 hover:border-primary-500"
|
||||||
{{ partial "icon.html" "sun" }}
|
title="Switch to light appearance"
|
||||||
</button>
|
>
|
||||||
</div>
|
{{ partial "icon.html" "sun" }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{/* Extend footer - eg. for extra scripts, etc. */}}
|
{{/* Extend footer - eg. for extra scripts, etc. */}}
|
||||||
{{ if templates.Exists "partials/extend-footer.html" }}
|
{{ if templates.Exists "partials/extend-footer.html" }}
|
||||||
|
|
|
@ -62,24 +62,31 @@
|
||||||
integrity="{{ $customStyles.Data.Integrity }}"
|
integrity="{{ $customStyles.Data.Integrity }}"
|
||||||
/>
|
/>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<script>
|
{{ if eq (.Site.Params.darkMode | default "auto") "auto" }}
|
||||||
function loadPreferredScheme() {
|
<script>
|
||||||
if (localStorage.preferredScheme === 'dark' || (!('preferredScheme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
function loadPreferredAppearance() {
|
||||||
document.documentElement.classList.add('dark');
|
if (localStorage.preferredAppearance === "dark" || (!("preferredAppearance" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)) {
|
||||||
} else {
|
document.documentElement.classList.add("dark");
|
||||||
document.documentElement.classList.remove('dark');
|
} else {
|
||||||
|
document.documentElement.classList.remove("dark");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
function setPreferredAppearance(scheme) {
|
||||||
function setPreferredScheme(scheme) {
|
if (scheme == "default") {
|
||||||
if (scheme == "default") {
|
localStorage.removeItem("preferredAppearance");
|
||||||
localStorage.removeItem("preferredScheme");
|
} else {
|
||||||
} else {
|
localStorage.preferredAppearance = scheme;
|
||||||
localStorage.preferredScheme = scheme;
|
}
|
||||||
|
loadPreferredAppearance();
|
||||||
}
|
}
|
||||||
loadPreferredScheme();
|
loadPreferredAppearance();
|
||||||
}
|
window.matchMedia("(prefers-color-scheme: dark)").addListener(loadPreferredAppearance);
|
||||||
loadPreferredScheme();
|
</script>
|
||||||
</script>
|
{{ else }}
|
||||||
|
<script>
|
||||||
|
localStorage.removeItem("preferredAppearance");
|
||||||
|
</script>
|
||||||
|
{{ end }}
|
||||||
{{/* Icons */}}
|
{{/* Icons */}}
|
||||||
{{ if templates.Exists "partials/favicons.html" }}
|
{{ if templates.Exists "partials/favicons.html" }}
|
||||||
{{ partialCached "favicons.html" .Site }}
|
{{ partialCached "favicons.html" .Site }}
|
||||||
|
|
Loading…
Reference in New Issue