1
0
Fork 0
hugo-paper/layouts/partials/header.html

52 lines
1.5 KiB
HTML
Raw Normal View History

2021-08-23 21:59:02 +02:00
<header class="header">
{{ if .IsHome }}
<h1 class="logo">
2021-08-24 14:35:04 +02:00
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-dark"></a>
2021-08-23 21:59:02 +02:00
</h1>
{{ else }}
<p class="logo">
2021-08-24 14:35:04 +02:00
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-dark"></a>
2021-08-23 21:59:02 +02:00
</p>
{{ end }}
<script>
2021-08-24 14:35:04 +02:00
let bodyClx = document.body.classList;
let btnDark = document.querySelector('.btn-dark');
let sysDark = window.matchMedia('(prefers-color-scheme: dark)');
let darkVal = localStorage.getItem('dark');
2021-08-23 21:59:02 +02:00
2021-08-24 14:35:04 +02:00
let setDark = (isDark) => {
bodyClx[isDark ? 'add' : 'remove']('dark');
localStorage.setItem('dark', isDark ? 'yes' : 'no');
2021-08-23 21:59:02 +02:00
};
2021-08-24 14:35:04 +02:00
setDark(darkVal ? darkVal === 'yes' : sysDark.matches);
requestAnimationFrame(() => bodyClx.remove('not-ready'));
2021-08-23 21:59:02 +02:00
2021-08-24 14:35:04 +02:00
btnDark.addEventListener('click', () => setDark(!bodyClx.contains('dark')));
sysDark.addEventListener('change', (event) => setDark(event.matches));
2021-08-23 21:59:02 +02:00
</script>
{{ $url := .RelPermalink }}<!---->
{{ with site.Menus.main }}
<nav class="menu">
{{ range . }}
<a class="{{ if eq .URL $url }}active{{ end }}" href="{{ .URL }}">{{ .Name }}</a>
2021-08-22 02:36:17 +02:00
{{ end }}
2021-08-23 21:59:02 +02:00
</nav>
{{ end }}<!---->
2021-08-24 04:56:07 +02:00
{{ with $.Scratch.Get "social-list" }}
2021-08-23 21:59:02 +02:00
<nav class="social">
2021-08-24 04:56:07 +02:00
{{ range . }}
2021-08-23 21:59:02 +02:00
<a
2021-08-24 04:56:07 +02:00
class="{{ . }}"
style="--url: url(./{{ . }}.svg)"
href="https://{{ . }}.com/{{ site.Params.Get . }}"
2021-08-23 21:59:02 +02:00
target="_blank"
></a>
2021-08-20 13:21:20 +02:00
{{ end }}
2021-08-23 21:59:02 +02:00
</nav>
{{ end }}
</header>