diff --git a/package.json b/package.json index 7a152f6..0791bbd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "start": "astro dev", "build": "astro build", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "build-preview": "astro build && astro preview" }, "dependencies": { "@astrojs/mdx": "^2.2.0", diff --git a/src/components/navigation/Navigation.astro b/src/components/navigation/Navigation.astro index 23bd378..ece82cb 100644 --- a/src/components/navigation/Navigation.astro +++ b/src/components/navigation/Navigation.astro @@ -3,65 +3,67 @@ import NavigationItem from "./NavigationItem.astro"; import TagsMenu from "./TagsMenu.astro"; const { pathname } = Astro.url; -const currentUrl = pathname.replace(/^\/|\/$/g, ""); +const currentUrl = pathname.replace(/\/$/, '') -const isActive = (item: string) => { - return currentUrl.includes(item) -} +const isTagsActive = currentUrl === "tags" const navigationItems = [ - {label: 'Home', href: '/'}, {label: 'About', href: "/about"}, {label: 'Work', href: "/work"}] + { label: "Home", href: "/" }, + { label: "About", href: "/about" }, + { label: "Work", href: "/work" }, +]; --- diff --git a/src/components/navigation/NavigationItem.astro b/src/components/navigation/NavigationItem.astro index 2afde14..3cca63a 100644 --- a/src/components/navigation/NavigationItem.astro +++ b/src/components/navigation/NavigationItem.astro @@ -2,15 +2,13 @@ const { label, href } = Astro.props; const { pathname } = Astro.url; -const isActive = () => { - if(label === 'Home') { - return pathname.includes('blog') || pathname === "/" - } else return pathname === href -} - +const route = pathname.replace(/\/$/, '') +const isHome = route.includes('blog') || pathname === href +const isCurrent = route === href +const isActive = isHome || isCurrent --- - - {label} + + {label} \ No newline at end of file +