aboutsummaryrefslogtreecommitdiff
path: root/src/components/HeaderLink.astro
blob: c53880d5e84f084af90a19080fc53ecdc58ac951 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
---
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={"/astro-blog/" + href}
  class:list={[className, { active: isActive }]}
  {...props}
>
  <slot />
</a>
<style>
  a {
    display: inline-block;
    text-decoration: none;
  }
  a.active {
    font-weight: bolder;
    text-decoration: underline;
  }
</style>