Skip to content

Commit 7334524

Browse files
committed
fix blog post matching active nav and add active nav to page logo
1 parent 32b0e6a commit 7334524

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/layouts/Navigation.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import NavigationLink from "./NavigationLink.astro"
44
<header>
55
<nav>
66
<section class="left">
7-
<h2><a href="/" target="_self">UmYeah.dev</a></h2>
7+
<h2><NavigationLink href="/" target="_self">UmYeah.dev</NavigationLink></h2>
88
</section>
99

1010
<section>
11-
<NavigationLink href="/blog" target="_self">Blog</NavigationLink>
11+
<NavigationLink match="/posts" href="/blog" target="_self">Blog</NavigationLink>
12+
<NavigationLink href="/tags" target="_self">Tags</NavigationLink>
1213
</section>
1314
</nav>
1415
</header>

src/layouts/NavigationLink.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
import type { HTMLAttributes } from 'astro/types';
33
4-
type Props = HTMLAttributes<'a'>;
4+
type Props = HTMLAttributes<'a'> & {match?: string};
55
6-
const { href, class: className, ...props } = Astro.props;
6+
const { match, href, class: className, ...props } = Astro.props;
77
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '');
88
const subpath = pathname.match(/[^/]+/g);
9-
const isActive = href === pathname || href === '/' + (subpath?.[0] || '');
9+
const isActive = href === pathname || match === '/' + (subpath?.[0] || '') || href === '/' + (subpath?.[0] || '');
1010
---
1111

1212
<a href={href} class:list={[className, { active: isActive }]} {...props}>

0 commit comments

Comments
 (0)