This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { useComputed, useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
import { Home, NotebookPen, FileText, CodeXml, Terminal as TerminalIcon } from 'lucide-preact';
|
||||
import {
|
||||
Home,
|
||||
NotebookPen,
|
||||
FileText,
|
||||
CodeXml,
|
||||
Terminal as TerminalIcon,
|
||||
Megaphone,
|
||||
} from "lucide-preact";
|
||||
|
||||
interface NavigationBarProps {
|
||||
currentPath: string;
|
||||
@@ -10,7 +17,7 @@ export default function NavigationBar({ currentPath }: NavigationBarProps) {
|
||||
const isScrolling = useSignal(false);
|
||||
const prevScrollPos = useSignal(0);
|
||||
const currentClientPath = useSignal(currentPath);
|
||||
|
||||
|
||||
const isVisible = useComputed(() => {
|
||||
if (prevScrollPos.value < 50) return true;
|
||||
|
||||
@@ -35,28 +42,29 @@ export default function NavigationBar({ currentPath }: NavigationBarProps) {
|
||||
};
|
||||
|
||||
// Listen for astro:page-load event which fires after navigation completes
|
||||
document.addEventListener('astro:page-load', handleAstroNavigation);
|
||||
|
||||
document.addEventListener("astro:page-load", handleAstroNavigation);
|
||||
|
||||
// Also listen for astro:after-swap as a backup
|
||||
document.addEventListener('astro:after-swap', handleAstroNavigation);
|
||||
document.addEventListener("astro:after-swap", handleAstroNavigation);
|
||||
|
||||
// Listen for regular navigation events as fallback
|
||||
window.addEventListener('popstate', updatePath);
|
||||
window.addEventListener("popstate", updatePath);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('astro:page-load', handleAstroNavigation);
|
||||
document.removeEventListener('astro:after-swap', handleAstroNavigation);
|
||||
window.removeEventListener('popstate', updatePath);
|
||||
document.removeEventListener("astro:page-load", handleAstroNavigation);
|
||||
document.removeEventListener("astro:after-swap", handleAstroNavigation);
|
||||
window.removeEventListener("popstate", updatePath);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Use the client path
|
||||
const activePath = currentClientPath.value;
|
||||
|
||||
// Normalize path by removing trailing slashes for consistent comparison
|
||||
const normalizedPath = activePath.endsWith('/') && activePath.length > 1
|
||||
? activePath.slice(0, -1)
|
||||
: activePath;
|
||||
// Normalize path
|
||||
const normalizedPath =
|
||||
activePath.endsWith("/") && activePath.length > 1
|
||||
? activePath.slice(0, -1)
|
||||
: activePath;
|
||||
|
||||
const isPostsPath = (path: string) => {
|
||||
return path.startsWith("/posts") || path.startsWith("/post/");
|
||||
@@ -125,7 +133,9 @@ export default function NavigationBar({ currentPath }: NavigationBarProps) {
|
||||
<li class="mx-0.5 sm:mx-1">
|
||||
<a
|
||||
href="/projects"
|
||||
class={normalizedPath.startsWith("/projects") ? "menu-active" : ""}
|
||||
class={
|
||||
normalizedPath.startsWith("/projects") ? "menu-active" : ""
|
||||
}
|
||||
>
|
||||
<div class="tooltip" data-tip="Projects">
|
||||
<CodeXml size={18} class="sm:w-5 sm:h-5" />
|
||||
@@ -133,6 +143,17 @@ export default function NavigationBar({ currentPath }: NavigationBarProps) {
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="mx-0.5 sm:mx-1">
|
||||
<a
|
||||
href="/talks"
|
||||
class={normalizedPath.startsWith("/talks") ? "menu-active" : ""}
|
||||
>
|
||||
<div class="tooltip" data-tip="Talks">
|
||||
<Megaphone size={18} class="sm:w-5 sm:h-5" />
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="mx-0.5 sm:mx-1">
|
||||
<a
|
||||
href="/terminal"
|
||||
|
Reference in New Issue
Block a user