mirror of
https://github.com/kogakure/website-astro-stefanimhoff.de.git
synced 2026-02-03 20:15:27 +00:00
feat(astro): create Link component
This commit is contained in:
22
src/components/Link.astro
Normal file
22
src/components/Link.astro
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
import type { HTMLAttributes } from 'astro/types';
|
||||
|
||||
type Props = HTMLAttributes<'a'>;
|
||||
|
||||
const props = { ...Astro.props };
|
||||
const { class: className } = props;
|
||||
|
||||
if (typeof props.href !== 'string') props.href = '#';
|
||||
|
||||
const isExternal = props.href.startsWith('http');
|
||||
---
|
||||
|
||||
<a
|
||||
class:list={['link', className, { external: isExternal }]}
|
||||
href={props.href}
|
||||
rel={isExternal ? 'nofollow noopener noreferrer' : null}
|
||||
target={isExternal ? '_blank' : null}
|
||||
{...props}
|
||||
>
|
||||
<slot />
|
||||
</a>
|
||||
Reference in New Issue
Block a user