all repos — website @ ee3e7babf40292bc0829f1e2e304a1a1364c1905

My official website.

src/components/SocialIcons.astro (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
---
import Link from '@/components/Link.astro'
import { buttonVariants } from '@/components/ui/button'
import type { Link as SocialLink } from '@/consts'
import { cn } from '@/lib/utils'
import { Icon } from 'astro-icon/components'

interface Props {
  links: SocialLink[]
  className?: string
}

const { links, className } = Astro.props

const iconMap = {
  Website: 'lucide:globe',
  GitHub: 'lucide:github',
  LinkedIn: 'lucide:linkedin',
  Fediverse: 'ph:fediverse-logo',
  Email: 'lucide:mail',
  RSS: 'lucide:rss',
}

const getSocialLink = ({ href, label }: SocialLink) => ({
  href: label === 'Email' ? `mailto:${href}` : href,
  ariaLabel: label,
  iconName:
    iconMap[label as keyof typeof iconMap] || 'lucide:message-circle-question',
})
---

<ul class={cn('not-prose flex flex-wrap gap-2', className)} role="list">
  {
    links.map((link) => {
      const { href, ariaLabel, iconName } = getSocialLink(link)
      return (
        <li>
          <Link
            href={href}
            aria-label={ariaLabel}
            title={ariaLabel}
            class={buttonVariants({ variant: 'outline', size: 'icon' })}
            external
          >
            <Icon name={iconName} class="size-4" />
          </Link>
        </li>
      )
    })
  }
</ul>