Files
codey.lol/src/layouts/Nav.astro

97 lines
3.4 KiB
Plaintext
Raw Normal View History

2025-06-18 07:46:59 -04:00
---
import { metaData } from "../config";
import { Icon } from "astro-icon/components";
import ExitToApp from '@mui/icons-material/ExitToApp';
const navItems = [
{ label: "Home", href: "/" },
{ label: "Radio", href: "/radio" },
2025-07-24 10:35:43 -04:00
{ label: "Memes", href: "/memes" },
2025-08-09 07:10:04 -04:00
{ label: "TRip", href: "/TRip", auth: true },
{ label: "Status", href: "https://status.boatson.boats", icon: ExitToApp },
{ label: "Git", href: "https://kode.boatson.boats", icon: ExitToApp },
];
2025-08-09 07:10:04 -04:00
const currentPath = Astro.url.pathname;
2025-06-18 07:46:59 -04:00
---
<script is:inline>
toggleTheme = () => {
const currentTheme = document.documentElement.getAttribute("data-theme");
const newTheme = currentTheme === "dark" ? "light" : "dark";
document.dispatchEvent(new CustomEvent("set-theme", { detail: newTheme }));
}
</script>
<nav class="w-full px-4 py-4 bg-transparent">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<a href="/" class="text-xl font-semibold header-text whitespace-nowrap">
{metaData.title}
</a>
<ul class="flex flex-wrap items-center gap-2 text-sm text-neutral-700 dark:text-neutral-300">
{navItems.map((item, index) => {
2025-08-09 07:10:04 -04:00
// if (item.blockSeparator) {
// return (
// <li class="text-neutral-500 dark:text-neutral-500 px-2 select-none" aria-hidden="true">
// ‖
// </li>
// );
// }
2025-06-18 07:46:59 -04:00
const isExternal = item.href?.startsWith("http");
2025-08-09 07:10:04 -04:00
const isAuthedPath = item.auth ?? false;
const normalize = (url) => (url || '/').replace(/\/+$/, '') || '/';
const normalizedCurrent = normalize(currentPath);
const normalizedHref = normalize(item.href);
2025-08-20 15:57:59 -04:00
const isActive = !isExternal && (
normalizedHref === '/'
? normalizedCurrent === '/' // Home only matches exact /
: normalizedCurrent === normalizedHref || normalizedCurrent.startsWith(normalizedHref + '/')
);
2025-07-17 10:43:50 -04:00
const nextItem = navItems[index + 1];
2025-08-09 07:10:04 -04:00
const shouldShowThinBar = nextItem //&& !nextItem.blockSeparator;
2025-06-18 07:46:59 -04:00
return (
<>
<li>
<a
href={item.href}
class={`flex items-center gap-1 px-2 py-1 rounded-md transition-colors
hover:bg-neutral-200 dark:hover:bg-neutral-800
${isActive ? "font-semibold underline underline-offset-4" : ""}`}
target={isExternal ? "_blank" : undefined}
2025-08-09 07:10:04 -04:00
rel={(isExternal || isAuthedPath) ? "external" : undefined}
>
{item.label}
{item.icon === ExitToApp && <ExitToApp className="w-4 h-4" client:load />}
</a>
</li>
{shouldShowThinBar && (
2025-07-17 10:38:58 -04:00
<li class="text-neutral-400 dark:text-neutral-600 select-none" aria-hidden="true">
|
</li>
2025-07-17 10:38:58 -04:00
)}
</>
);
})}
<li>
<button
id="theme-toggle"
aria-label="Toggle theme"
type="button"
class="flex items-center justify-center px-2 py-1 rounded-md hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-opacity"
onclick="toggleTheme()"
>
<Icon
name="fa6-solid:circle-half-stroke"
class="h-4 w-4 text-[#1c1c1c] dark:text-[#D4D4D4]"
/>
</button>
</li>
</ul>
2025-06-18 07:46:59 -04:00
</div>
</nav>