2023-09-26 14:27:38 +08:00
|
|
|
---
|
|
|
|
import Button from "./control/Button.astro";
|
|
|
|
import { Icon } from 'astro-icon/components';
|
2023-10-02 01:52:08 +08:00
|
|
|
import DisplaySetting from "./widget/DisplaySetting.astro";
|
2023-10-06 02:53:47 +08:00
|
|
|
import I18nKey from "../i18n/i18nKey";
|
|
|
|
import {i18n} from "../i18n/translation";
|
2023-10-23 17:45:07 +08:00
|
|
|
import {LinkPreset, NavBarLink} from "../types/config";
|
|
|
|
import {navBarConfig, siteConfig} from "../config";
|
2023-09-26 14:27:38 +08:00
|
|
|
const className = Astro.props.class;
|
2023-10-06 02:53:47 +08:00
|
|
|
|
|
|
|
function isI18nKey(key: string): key is I18nKey {
|
|
|
|
return Object.values(I18nKey).includes(key);
|
|
|
|
}
|
|
|
|
|
2023-10-23 17:45:07 +08:00
|
|
|
let links: NavBarLink[] = navBarConfig.links.map((item) => {
|
|
|
|
if (typeof item === "number") {
|
|
|
|
return getLinkPresetInfo(item)
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
|
|
|
|
function getLinkPresetInfo(p: LinkPreset): NavBarLink {
|
|
|
|
switch (p) {
|
|
|
|
case LinkPreset.Home:
|
|
|
|
return {
|
|
|
|
name: i18n(I18nKey.home),
|
|
|
|
url: "/page/1"
|
|
|
|
};
|
|
|
|
case LinkPreset.Archive:
|
|
|
|
return {
|
|
|
|
name: i18n(I18nKey.archive),
|
|
|
|
url: "/archive"
|
|
|
|
};
|
|
|
|
case LinkPreset.About:
|
|
|
|
return {
|
|
|
|
name: i18n(I18nKey.about),
|
|
|
|
url: "/about"
|
|
|
|
};
|
2023-10-06 02:53:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 14:27:38 +08:00
|
|
|
---
|
2023-10-11 22:29:23 +08:00
|
|
|
<div transition:animate="none" class:list={[
|
2023-09-26 14:27:38 +08:00
|
|
|
className,
|
2023-10-11 22:29:23 +08:00
|
|
|
"card-base sticky top-0 overflow-visible max-w-[var(--page-width)] h-[72px] rounded-t-none mx-auto flex items-center justify-between px-4"]}>
|
2023-10-16 22:45:30 +08:00
|
|
|
<a href="/page/1"><Button height="52px" class="px-5 font-bold rounded-lg active:scale-95" light>
|
2023-09-26 14:27:38 +08:00
|
|
|
<div class="flex flex-row text-[var(--primary)] items-center text-md">
|
|
|
|
<Icon name="material-symbols:home-outline-rounded" size={28} class="mb-1 mr-2" />
|
2023-10-23 17:45:07 +08:00
|
|
|
{siteConfig.title}
|
2023-09-26 14:27:38 +08:00
|
|
|
</div>
|
|
|
|
</Button></a>
|
|
|
|
<div>
|
2023-10-23 17:45:07 +08:00
|
|
|
{links.map((l) => {
|
2023-11-03 15:59:14 +08:00
|
|
|
return <a aria-label={l.name} href={l.url} target={l.external ? "_blank" : null}>
|
|
|
|
<Button light class="font-bold px-5 rounded-lg active:scale-95">
|
|
|
|
<div class="flex items-center">
|
|
|
|
{l.name}
|
|
|
|
{l.external && <Icon size="14" name="fa6-solid:arrow-up-right-from-square" class="transition -translate-y-[1px] ml-1 text-black/[0.2] dark:text-white/[0.2]"></Icon>}
|
|
|
|
</div>
|
|
|
|
</Button>
|
|
|
|
</a>;
|
2023-10-06 02:53:47 +08:00
|
|
|
})}
|
2023-09-26 14:27:38 +08:00
|
|
|
</div>
|
2023-10-02 01:52:08 +08:00
|
|
|
<div class="flex">
|
|
|
|
<div>
|
2023-10-20 11:36:55 +08:00
|
|
|
<Button name="Display Settings" class="rounded-lg active:scale-90" id="display-settings-switch" iconName="material-symbols:palette-outline" iconSize={20} isIcon light></Button>
|
2023-10-02 01:52:08 +08:00
|
|
|
</div>
|
|
|
|
<div>
|
2023-10-20 11:36:55 +08:00
|
|
|
<Button name="Light/Dark Mode" class="rounded-lg flex items-center justify-center active:scale-90" id="scheme-switch" light height="44px" width="44px">
|
2023-10-04 18:02:00 +08:00
|
|
|
<Icon name="material-symbols:wb-sunny-outline-rounded" size={20} class="absolute opacity-[var(--display-light-icon)]"></Icon>
|
|
|
|
<Icon name="material-symbols:dark-mode-outline-rounded" size={20} class="absolute opacity-[var(--display-dark-icon)]"></Icon>
|
|
|
|
</Button>
|
2023-10-02 01:52:08 +08:00
|
|
|
</div>
|
2023-09-26 14:27:38 +08:00
|
|
|
</div>
|
2023-10-02 01:52:08 +08:00
|
|
|
<DisplaySetting></DisplaySetting>
|
2023-09-26 14:27:38 +08:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="stylus">
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
function switchTheme() {
|
|
|
|
if (localStorage.theme === 'dark') {
|
|
|
|
document.documentElement.classList.remove('dark');
|
|
|
|
localStorage.theme = 'light';
|
|
|
|
} else {
|
|
|
|
document.documentElement.classList.add('dark');
|
|
|
|
localStorage.theme = 'dark';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadThemeSwitchScript() {
|
|
|
|
let switchBtn = document.getElementById("scheme-switch");
|
|
|
|
switchBtn.addEventListener("click", function () {
|
|
|
|
switchTheme()
|
|
|
|
});
|
2023-10-02 01:52:08 +08:00
|
|
|
|
|
|
|
let settingBtn = document.getElementById("display-settings-switch");
|
|
|
|
settingBtn.addEventListener("click", function () {
|
|
|
|
let settingPanel = document.getElementById("display-setting");
|
|
|
|
settingPanel.classList.toggle("closed");
|
|
|
|
});
|
2023-09-26 14:27:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
loadThemeSwitchScript();
|
|
|
|
|
|
|
|
document.addEventListener('astro:after-swap', () => {
|
|
|
|
loadThemeSwitchScript();
|
|
|
|
}, { once: false });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|