1
0
Fork 0
hugo-paper/layouts/partials/header.html
nanxiaobei 39f6f4e9b2 v6
2022-07-18 23:36:39 +08:00

82 lines
2.9 KiB
HTML

<header class="mx-auto flex h-[5rem] max-w-3xl px-8 lg:justify-center">
<div class="relative z-50 mr-auto flex items-center">
<a class="-translate-x-[1px] -translate-y-0.5 text-3xl font-bold" href="{{ `` | absURL }}"
>{{ site.Title }}</a
>
<a
class="btn-dark ml-7 h-[1.4rem] w-[1.4rem] shrink-0 cursor-pointer [background:url(./theme.svg)_left_center/cover_no-repeat] dark:invert dark:[background-position:right]"
></a>
</div>
<a
class="btn-menu relative z-50 -mr-8 flex h-[5rem] w-[5rem] shrink-0 cursor-pointer flex-col items-center justify-center gap-2.5 lg:hidden"
></a>
<script>
const metaTheme = document.querySelector('meta[name="theme-color"]');
const htmlClass = document.documentElement.classList;
requestAnimationFrame(() => {
htmlClass.remove('not-ready');
});
const setDark = (newDark) => {
metaTheme.setAttribute('content', newDark ? '#000' : '#FCFAF9');
htmlClass[newDark ? 'add' : 'remove']('dark');
localStorage.setItem('dark', newDark);
};
// init
const darkScheme = window.matchMedia('(prefers-color-scheme: dark)');
const darkVal = localStorage.getItem('dark');
setDark(darkVal ? darkVal === 'true' : darkScheme.matches);
// listen system
darkScheme.addEventListener('change', (event) => {
setDark(event.matches);
});
// manual switch
const btnDark = document.querySelector('.btn-dark');
btnDark.addEventListener('click', () => {
setDark(localStorage.getItem('dark') !== 'true');
});
// mobile menu
const btnMenu = document.querySelector('.btn-menu');
btnMenu.addEventListener('click', () => {
htmlClass.toggle('open');
});
</script>
<div
class="nav-wrapper fixed inset-x-0 top-full z-40 flex h-full select-none flex-col justify-center pb-16 duration-200 dark:bg-black lg:static lg:h-auto lg:flex-row lg:!bg-transparent lg:pb-0 lg:transition-none"
>
{{ $url := .RelPermalink }}<!---->
{{ with site.Menus.main }}
<nav class="lg:ml-14 lg:flex lg:flex-row lg:items-center lg:space-x-7">
{{ range . }}
<a
class="block font-medium lg:font-normal text-center leading-[5rem] text-3xl lg:text-base {{ if eq .URL $url }}active{{ end }}"
href="{{ .URL }}"
>{{ .Name }}</a
>
{{ end }}
</nav>
{{ end }}<!---->
{{ with $.Scratch.Get "social_list" }}
<nav
class="mt-12 flex justify-center space-x-10 dark:invert lg:mt-0 lg:ml-14 lg:items-center lg:space-x-7"
>
{{ range . }}<!---->
<a
class="h-8 w-8 [background:var(--url)_center_center/cover_no-repeat] lg:h-6 lg:w-6"
style="--url: url(./{{ . }}.svg)"
href="{{ if eq . `rss` }} {{ `index.xml` | absURL }} {{ else }} https://{{ . }}.com/{{ site.Params.Get . }} {{ end }}"
target="_blank"
></a>
{{ end }}<!---->
</nav>
{{ end }}<!---->
</div>
</header>