summaryrefslogtreecommitdiff
path: root/src/components/HeaderLink.astro
diff options
context:
space:
mode:
authorhouston[bot] <astrobot-houston@users.noreply.github.com>2025-10-19 18:30:51 +0200
committerMatthieu Pignolet <matthieu@puffer.fish>2025-10-19 18:30:51 +0200
commite435718c4dd6e956dc1748689a6156129650c250 (patch)
tree575ab9929930553253b9cf0a8b8843d48d7e6867 /src/components/HeaderLink.astro
Initial commit from Astro
Diffstat (limited to 'src/components/HeaderLink.astro')
-rw-r--r--src/components/HeaderLink.astro24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/components/HeaderLink.astro b/src/components/HeaderLink.astro
new file mode 100644
index 0000000..41da846
--- /dev/null
+++ b/src/components/HeaderLink.astro
@@ -0,0 +1,24 @@
+---
+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>
+<style>
+ a {
+ display: inline-block;
+ text-decoration: none;
+ }
+ a.active {
+ font-weight: bolder;
+ text-decoration: underline;
+ }
+</style>