Remove JavaScript from the header template
This commit is contained in:
parent
ed0a37035d
commit
3de9cb7a5e
1 changed files with 2 additions and 20 deletions
|
@ -1,32 +1,14 @@
|
||||||
<header class="header">
|
<header class="header">
|
||||||
{{ if .IsHome }}
|
{{ if .IsHome }}
|
||||||
<h1 class="logo">
|
<h1 class="logo">
|
||||||
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-dark"></a>
|
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a>
|
||||||
</h1>
|
</h1>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<p class="logo">
|
<p class="logo">
|
||||||
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-dark"></a>
|
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a>
|
||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<script>
|
|
||||||
let bodyClx = document.body.classList;
|
|
||||||
let btnDark = document.querySelector('.btn-dark');
|
|
||||||
let sysDark = window.matchMedia('(prefers-color-scheme: dark)');
|
|
||||||
let darkVal = localStorage.getItem('dark');
|
|
||||||
|
|
||||||
let setDark = (isDark) => {
|
|
||||||
bodyClx[isDark ? 'add' : 'remove']('dark');
|
|
||||||
localStorage.setItem('dark', isDark ? 'yes' : 'no');
|
|
||||||
};
|
|
||||||
|
|
||||||
setDark(darkVal ? darkVal === 'yes' : sysDark.matches);
|
|
||||||
requestAnimationFrame(() => bodyClx.remove('not-ready'));
|
|
||||||
|
|
||||||
btnDark.addEventListener('click', () => setDark(!bodyClx.contains('dark')));
|
|
||||||
sysDark.addEventListener('change', (event) => setDark(event.matches));
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{{ $url := .RelPermalink }}<!---->
|
{{ $url := .RelPermalink }}<!---->
|
||||||
{{ with site.Menus.main }}
|
{{ with site.Menus.main }}
|
||||||
<nav class="menu">
|
<nav class="menu">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue