feat(astro): create Link component

This commit is contained in:
Stefan Imhoff
2023-02-27 18:25:45 +01:00
parent c3998b9239
commit a297452050
7 changed files with 47 additions and 17 deletions

22
src/components/Link.astro Normal file
View 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>