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

81 lines
3 KiB
HTML
Raw Normal View History

2022-07-18 17:36:39 +02:00
<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
2022-07-19 17:25:41 +02:00
class="btn-dark ml-6 h-6 w-6 shrink-0 cursor-pointer {{ if site.Params.monoDarkIcon }}[background:url(./theme.svg)_left_center/cover_no-repeat] dark:invert{{ else }}[background:url(./theme.png)_left_center/_auto_theme('spacing.6')_no-repeat] [transition:_background-position_0.4s_steps(5)]{{ end }} dark:[background-position:right]"
2022-07-18 17:36:39 +02:00
></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>
2021-08-23 21:59:02 +02:00
<script>
2022-07-18 17:36:39 +02:00
const metaTheme = document.querySelector('meta[name="theme-color"]');
const htmlClass = document.documentElement.classList;
2022-07-19 17:25:41 +02:00
setTimeout(() => htmlClass.remove('not-ready'), 10);
2022-07-18 17:36:39 +02:00
const setDark = (newDark) => {
2022-07-19 17:25:41 +02:00
metaTheme.setAttribute('content', newDark ? 'var(--dark-bg)' : 'var(--light-bg)');
2022-07-18 17:36:39 +02:00
htmlClass[newDark ? 'add' : 'remove']('dark');
localStorage.setItem('dark', newDark);
2021-08-23 21:59:02 +02:00
};
2022-07-18 17:36:39 +02:00
// 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);
});
2021-08-23 21:59:02 +02:00
2022-07-18 17:36:39 +02:00
// 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');
});
2021-08-23 21:59:02 +02:00
</script>
2022-07-18 17:36:39 +02:00
<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 }}
2022-07-18 21:49:32 +02:00
<nav class="lg:ml-12 lg:flex lg:flex-row lg:items-center lg:space-x-6">
2022-07-18 17:36:39 +02:00
{{ 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
2022-07-18 21:49:32 +02:00
class="mt-12 flex justify-center space-x-10 dark:invert lg:mt-0 lg:ml-12 lg:items-center lg:space-x-6"
2022-07-18 17:36:39 +02:00
>
{{ 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>
2021-08-23 21:59:02 +02:00
</header>