18 lines
381 B
Plaintext
18 lines
381 B
Plaintext
---
|
|
export type Props = astroHTML.JSX.AnchorHTMLAttributes & {
|
|
href: string
|
|
}
|
|
|
|
const removeTrailingSlash = (str: string) => str.replace(/\/$/, "")
|
|
|
|
const linkUrl = new URL(Astro.props.href, Astro.url)
|
|
|
|
const isActive =
|
|
removeTrailingSlash(Astro.url.pathname) ===
|
|
removeTrailingSlash(linkUrl.pathname)
|
|
---
|
|
|
|
<a {...Astro.props} data-active={isActive || undefined}>
|
|
<slot />
|
|
</a>
|