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

98 lines
3.4 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">
2022-11-15 01:06:02 +01:00
<a
class="-translate-x-[1px] -translate-y-0.5 text-3xl font-bold"
href="{{ `/` | absURL }}"
2022-07-18 17:36:39 +02:00
>{{ site.Title }}</a
>
2023-02-24 18:51:26 +01:00
<div
2023-02-24 18:18:10 +01:00
class="btn-dark text-[0] 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]"
2023-02-24 18:55:38 +01:00
role="button"
2023-02-24 18:51:26 +01:00
></div>
2022-07-18 17:36:39 +02:00
</div>
2023-02-24 18:51:26 +01:00
<div
2022-07-18 17:36:39 +02:00
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"
2023-02-24 18:55:38 +01:00
role="button"
2023-02-24 18:51:26 +01:00
></div>
2021-08-23 21:59:02 +02:00
2022-08-21 07:57:54 +02:00
{{ $bg_color := $.Scratch.Get "bg_color" }}
2021-08-23 21:59:02 +02:00
<script>
2022-08-15 20:20:41 +02:00
// base
2022-07-18 17:36:39 +02:00
const htmlClass = document.documentElement.classList;
2022-08-15 20:20:41 +02:00
setTimeout(() => {
htmlClass.remove('not-ready');
}, 10);
// mobile menu
const btnMenu = document.querySelector('.btn-menu');
btnMenu.addEventListener('click', () => {
htmlClass.toggle('open');
});
2022-07-18 17:36:39 +02:00
2022-08-15 20:20:41 +02:00
// dark theme
const metaTheme = document.querySelector('meta[name="theme-color"]');
2022-08-21 07:57:54 +02:00
const lightBg = `{{ $.Scratch.Get "bg_color" }}`.replace(/"/g, '');
2022-08-15 20:20:41 +02:00
const setDark = (isDark) => {
metaTheme.setAttribute('content', isDark ? '#000' : lightBg);
htmlClass[isDark ? 'add' : 'remove']('dark');
localStorage.setItem('dark', isDark);
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)');
2022-10-24 15:31:58 +02:00
if (htmlClass.contains('dark')) {
setDark(true);
} else {
const darkVal = localStorage.getItem('dark');
setDark(darkVal ? darkVal === 'true' : darkScheme.matches);
}
2022-07-18 17:36:39 +02:00
// 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');
});
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
2022-07-20 19:57:38 +02:00
class="block text-center text-2xl leading-[5rem] lg:text-base lg:font-normal"
2022-07-18 17:36:39 +02:00
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
2023-02-24 18:18:10 +01:00
class="h-8 w-8 text-[0] [background:var(--url)_center_center/cover_no-repeat] lg:h-6 lg:w-6"
2022-07-18 17:36:39 +02:00
style="--url: url(./{{ . }}.svg)"
2023-02-08 20:48:55 +01:00
href="{{ if eq . `rss` }}{{ `index.xml` | absURL }}{{ else if eq . `mastodon` }}{{ site.Params.Get . }}{{ else }}https://{{ . }}.com/{{ site.Params.Get . }}{{ end }}"
2022-07-18 17:36:39 +02:00
target="_blank"
2023-02-24 18:18:10 +01:00
rel="{{ if eq . `rss` }}alternate{{ else }}me{{ end }}"
>
{{ . }}
</a>
2022-07-18 17:36:39 +02:00
{{ end }}<!---->
</nav>
{{ end }}<!---->
</div>
2021-08-23 21:59:02 +02:00
</header>