Files
blog/src/components/HeaderLink.astro
2025-02-07 12:50:32 +01:00

15 lines
437 B
Plaintext

---
import type { HTMLAttributes } from "astro/types";
type Props = HTMLAttributes<"a">;
const { href, class: className, ...props } = Astro.props;
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, "");
const subpath = pathname.match(/[^\/]+/g);
const isActive = href === pathname || href === "/" + (subpath?.[0] || "");
---
<a href={href} class:list={[className, { active: isActive }]} {...props}>
<slot />
</a>