From a297452050a3098306dd2dbe9b28f67c3a351428 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Mon, 27 Feb 2023 18:25:45 +0100 Subject: [PATCH] feat(astro): create Link component --- src/components/Backlink.astro | 5 +++-- src/components/Link.astro | 22 ++++++++++++++++++++++ src/components/MainNavigation.astro | 6 ++++-- src/components/RSSLink.astro | 6 +++--- src/components/SocialLinks.astro | 9 +++++---- src/components/Subnavigation.astro | 10 ++++++---- src/components/UpLink.astro | 6 ++++-- 7 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 src/components/Link.astro diff --git a/src/components/Backlink.astro b/src/components/Backlink.astro index 397f55d..028aca7 100644 --- a/src/components/Backlink.astro +++ b/src/components/Backlink.astro @@ -1,5 +1,6 @@ --- import { Sprite } from 'astro-icon'; +import Link from '../components/Link.astro'; export interface Props { backLink?: string; @@ -10,7 +11,7 @@ const { backLink } = Astro.props; { backLink && ( - @@ -21,6 +22,6 @@ const { backLink } = Astro.props; > - + ) } diff --git a/src/components/Link.astro b/src/components/Link.astro new file mode 100644 index 0000000..9ff933e --- /dev/null +++ b/src/components/Link.astro @@ -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'); +--- + + + + diff --git a/src/components/MainNavigation.astro b/src/components/MainNavigation.astro index 1242308..2fa6db9 100644 --- a/src/components/MainNavigation.astro +++ b/src/components/MainNavigation.astro @@ -1,4 +1,6 @@ --- +import Link from './Link.astro'; + import navigation from '../data/navigation.json'; const currentPath = new URL(Astro.request.url).pathname; @@ -9,14 +11,14 @@ const currentPath = new URL(Astro.request.url).pathname; { navigation.map(({ title, url }) => (
  • - {title} - +
  • )) } diff --git a/src/components/RSSLink.astro b/src/components/RSSLink.astro index 34d25e9..73a43c9 100644 --- a/src/components/RSSLink.astro +++ b/src/components/RSSLink.astro @@ -1,6 +1,7 @@ --- import { Sprite } from 'astro-icon'; +import Link from './Link.astro'; import Subsubheadline from './Subsubheadline.astro'; --- @@ -8,13 +9,12 @@ import Subsubheadline from './Subsubheadline.astro'; Stay up to date.

    - Subscribe via RSS - +

    diff --git a/src/components/SocialLinks.astro b/src/components/SocialLinks.astro index 5f2568a..320dff0 100644 --- a/src/components/SocialLinks.astro +++ b/src/components/SocialLinks.astro @@ -1,22 +1,23 @@ --- import { Sprite } from 'astro-icon'; + +import Link from './Link.astro'; + import data from '../data/social-links.json'; ---
    { data.map(({ text, url, icon, props = {} }) => ( - - + )) }
    diff --git a/src/components/Subnavigation.astro b/src/components/Subnavigation.astro index 46211c8..7dca0e4 100644 --- a/src/components/Subnavigation.astro +++ b/src/components/Subnavigation.astro @@ -1,6 +1,8 @@ --- import data from '../data/subnavigation.json'; +import Link from './Link.astro'; + const currentPath = new URL(Astro.request.url).pathname; --- @@ -9,14 +11,14 @@ const currentPath = new URL(Astro.request.url).pathname; { data.main.map(({ title, url }) => (
  • - {title} - +
  • )) } @@ -25,14 +27,14 @@ const currentPath = new URL(Astro.request.url).pathname; { data.misc.map(({ title, url }) => (
  • - {title} - +
  • )) } diff --git a/src/components/UpLink.astro b/src/components/UpLink.astro index 5e5a4c2..3f29285 100644 --- a/src/components/UpLink.astro +++ b/src/components/UpLink.astro @@ -1,9 +1,11 @@ --- import { Sprite } from 'astro-icon'; + +import Link from './Link.astro'; ---
    - - +