web/src/components/HeaderLink.astro
2024-05-05 16:19:04 -04:00

24 lines
515 B
Text

---
import type { HTMLAttributes } from 'astro/types';
type Props = HTMLAttributes<'a'>;
const { href, class: className, ...props } = Astro.props;
const { pathname } = Astro.url;
const subpath = pathname.match(/[^\/]+/g);
const isActive = href === pathname || href === '/' + subpath?.[0];
---
<a href={href} class:list={[className, { active: isActive }]} {...props}>
<slot />
</a>
<style>
a {
@apply inline-block no-underline;
}
a.active {
font-weight: bolder;
text-decoration: underline;
}
</style>