Update themes/mytheme/layouts/partials/header.html

This commit is contained in:
Morgan 2023-10-29 16:26:45 +09:00
parent fac89dc363
commit 60f2f31692
1 changed files with 42 additions and 0 deletions

View File

@ -1,3 +1,45 @@
{{- /* theme-toggle is enabled */}}
{{- if (not site.Params.disableThemeToggle) }}
{{- /* theme is light */}}
{{- if (eq site.Params.defaultTheme "light") }}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
}
</script>
{{- /* theme is dark */}}
{{- else if (eq site.Params.defaultTheme "dark") }}
<script>
if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
}
</script>
{{- else }}
{{- /* theme is auto */}}
<script>
if (localStorage.getItem("pref-theme") === "dark") {
document.body.classList.add('dark');
} else if (localStorage.getItem("pref-theme") === "light") {
document.body.classList.remove('dark')
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}
</script>
{{- end }}
{{- /* theme-toggle is disabled and theme is auto */}}
{{- else if (and (ne site.Params.defaultTheme "light") (ne site.Params.defaultTheme "dark"))}}
<script>
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.body.classList.add('dark');
}
</script>
{{- end }}
<header class="header"> <header class="header">
<nav class="nav{{- if .IsHome }} nav-home{{- else if (not .IsPage) }} nav-nonpost{{- end }}"> <nav class="nav{{- if .IsHome }} nav-home{{- else if (not .IsPage) }} nav-nonpost{{- end }}">
<div class="logo"> <div class="logo">