Update themes/mytheme/layouts/partials/head.html
This commit is contained in:
parent
184d7cb8c4
commit
c550cc45d5
|
@ -185,3 +185,44 @@
|
||||||
{{- template "partials/templates/twitter_cards.html" . }}
|
{{- template "partials/templates/twitter_cards.html" . }}
|
||||||
{{- template "partials/templates/schema_json.html" . }}
|
{{- template "partials/templates/schema_json.html" . }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- /* 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 }}
|
Loading…
Reference in New Issue