blob: 7e705779941a1580ad6082741546cd32c0269498 [file] [log] [blame]
Samuel Shuert86826b82024-04-27 16:14:20 -04001---
2import type { HTMLAttributes } from 'astro/types';
3
4type Props = HTMLAttributes<'a'>;
5
6const { href, class: className, ...props } = Astro.props;
7
8const { pathname } = Astro.url;
9const subpath = pathname.match(/[^\/]+/g);
Samuel Shuert39632832024-04-29 20:54:19 -040010console.log(subpath, pathname)
Samuel Shuert86826b82024-04-27 16:14:20 -040011const isActive = href === pathname || href === '/' + subpath?.[0];
12---
13
14<a href={href} class:list={[className, { active: isActive }]} {...props}>
15 <slot />
16</a>
17<style>
18 a {
19 display: inline-block;
20 text-decoration: none;
21 }
22 a.active {
23 font-weight: bolder;
24 text-decoration: underline;
25 }
26</style>