~repos /website

#astro#js#html#css

git clone https://pyrossh.dev/repos/website.git

木 Personal website of pyrossh. Built with astrojs, shiki, vite.



src/components/HeaderLink.astro



---
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] || "");
const isExternal = href.startsWith("http");
const target = isExternal ? "_blank" : "_parent";
const rel = isExternal ? "noopener noreferrer" : "";
---
<a
href={href}
class:list={[className, { active: isActive }]}
rel={rel}
target={target}
{...props}
>
<slot />
</a>