parent
a11a99f92a
commit
8c6aa5ac09
3 changed files with 3 additions and 12 deletions
|
@ -14,11 +14,7 @@ window.addEventListener('load', async () => {
|
||||||
|
|
||||||
|
|
||||||
function loadScheme() {
|
function loadScheme() {
|
||||||
return localStorage.getItem(PERSISTENCE_KEY) || loadDefaultScheme()
|
return localStorage.getItem(PERSISTENCE_KEY) || "system"
|
||||||
}
|
|
||||||
|
|
||||||
function loadDefaultScheme() {
|
|
||||||
return document.getElementById('defaultTheme').innerText || "system"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveScheme(scheme) {
|
function saveScheme(scheme) {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<!--================= add analytics if enabled =========================-->
|
<!--================= add analytics if enabled =========================-->
|
||||||
{{- partial "analytics.html" . -}}
|
{{- partial "analytics.html" . -}}
|
||||||
<script>
|
<script>
|
||||||
theme = localStorage.getItem('darkmode:color-scheme') || document.getElementById('defaultTheme').innerText || "system"
|
theme = localStorage.getItem('darkmode:color-scheme') || 'system';
|
||||||
if (theme == 'system') {
|
if (theme == 'system') {
|
||||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
theme = 'dark';
|
theme = 'dark';
|
||||||
|
|
|
@ -3,18 +3,13 @@
|
||||||
<head>
|
<head>
|
||||||
<title>{{- .Site.Title -}}</title>
|
<title>{{- .Site.Title -}}</title>
|
||||||
{{ $siteDescription := .Site.Params.description }}
|
{{ $siteDescription := .Site.Params.description }}
|
||||||
{{ $siteDefaultTheme := .Site.Params.defaultTheme }}
|
|
||||||
{{ if (index .Site.Data .Site.Language.Lang).site }}
|
{{ if (index .Site.Data .Site.Language.Lang).site }}
|
||||||
{{ $siteConfig := (index .Site.Data .Site.Language.Lang).site }}
|
{{ $siteConfig := (index .Site.Data .Site.Language.Lang).site }}
|
||||||
{{ if $siteConfig.description }}
|
{{ if $siteConfig.description }}
|
||||||
{{ $siteDescription = $siteConfig.description }}
|
{{ $siteDescription = $siteConfig.description }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if $siteConfig.defaultTheme }}
|
|
||||||
{{ $siteDefaultTheme = $siteConfig.defaultTheme }}
|
|
||||||
{{ end }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<meta name="description" content="{{ $siteDescription }}" />
|
<meta name="description" content="{{ $siteDescription }}" />
|
||||||
<p id="defaultTheme" hidden>{{ $siteDefaultTheme }}</p>
|
|
||||||
|
|
||||||
<!-- import common headers -->
|
<!-- import common headers -->
|
||||||
{{- partial "header.html" . -}}
|
{{- partial "header.html" . -}}
|
||||||
|
@ -23,7 +18,7 @@
|
||||||
<!--================= add analytics if enabled =========================-->
|
<!--================= add analytics if enabled =========================-->
|
||||||
{{- partial "analytics.html" . -}}
|
{{- partial "analytics.html" . -}}
|
||||||
<script>
|
<script>
|
||||||
theme = localStorage.getItem('darkmode:color-scheme') || document.getElementById('defaultTheme').innerText || "system"
|
theme = localStorage.getItem('darkmode:color-scheme') || 'system';
|
||||||
if (theme == 'system') {
|
if (theme == 'system') {
|
||||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
theme = 'dark';
|
theme = 'dark';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue