|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { IconClass } from '~/types' |
| 3 | +
|
| 4 | +const props = defineProps<{ |
| 5 | + pkg: SlimPackument |
| 6 | + jsrInfo?: JsrPackageInfo |
| 7 | +}>() |
| 8 | +
|
| 9 | +const displayVersion = computed(() => props.pkg?.requestedVersion ?? null) |
| 10 | +const { repositoryUrl } = useRepositoryUrl(displayVersion) |
| 11 | +const { meta: repoMeta, repoRef, stars, starsLink, forks, forksLink } = useRepoMeta(repositoryUrl) |
| 12 | +const compactNumberFormatter = useCompactNumberFormatter() |
| 13 | +
|
| 14 | +const homepageUrl = computed(() => { |
| 15 | + const homepage = displayVersion.value?.homepage |
| 16 | + if (!homepage) return null |
| 17 | +
|
| 18 | + // Don't show homepage if it's the same as the repository URL |
| 19 | + if (repositoryUrl.value && areUrlsEquivalent(homepage, repositoryUrl.value)) { |
| 20 | + return null |
| 21 | + } |
| 22 | +
|
| 23 | + return homepage |
| 24 | +}) |
| 25 | +
|
| 26 | +const fundingUrl = computed(() => { |
| 27 | + let funding = displayVersion.value?.funding |
| 28 | + if (Array.isArray(funding)) funding = funding[0] |
| 29 | +
|
| 30 | + if (!funding) return null |
| 31 | +
|
| 32 | + return typeof funding === 'string' ? funding : funding.url |
| 33 | +}) |
| 34 | +
|
| 35 | +const PROVIDER_ICONS: Record<string, IconClass> = { |
| 36 | + github: 'i-simple-icons:github', |
| 37 | + gitlab: 'i-simple-icons:gitlab', |
| 38 | + bitbucket: 'i-simple-icons:bitbucket', |
| 39 | + codeberg: 'i-simple-icons:codeberg', |
| 40 | + gitea: 'i-simple-icons:gitea', |
| 41 | + forgejo: 'i-simple-icons:forgejo', |
| 42 | + gitee: 'i-simple-icons:gitee', |
| 43 | + sourcehut: 'i-simple-icons:sourcehut', |
| 44 | + tangled: 'i-custom:tangled', |
| 45 | + radicle: 'i-lucide:network', // Radicle is a P2P network, using network icon |
| 46 | +} |
| 47 | +
|
| 48 | +const repoProviderIcon = computed((): IconClass => { |
| 49 | + const provider = repoRef.value?.provider |
| 50 | + if (!provider) return 'i-simple-icons:github' |
| 51 | + return PROVIDER_ICONS[provider] ?? 'i-lucide:code' |
| 52 | +}) |
| 53 | +</script> |
| 54 | + |
| 55 | +<template> |
| 56 | + <ul class="flex flex-wrap items-center gap-x-3 gap-y-1.5 sm:gap-4 list-none m-0 p-0 mt-3 text-sm"> |
| 57 | + <li v-if="repositoryUrl"> |
| 58 | + <LinkBase :to="repositoryUrl" :classicon="repoProviderIcon"> |
| 59 | + <span v-if="repoRef"> |
| 60 | + {{ repoRef.owner }}<span class="opacity-50">/</span>{{ repoRef.repo }} |
| 61 | + </span> |
| 62 | + <span v-else>{{ $t('package.links.repo') }}</span> |
| 63 | + </LinkBase> |
| 64 | + </li> |
| 65 | + <li v-if="repositoryUrl && repoMeta && starsLink"> |
| 66 | + <LinkBase :to="starsLink" classicon="i-lucide:star"> |
| 67 | + {{ compactNumberFormatter.format(stars) }} |
| 68 | + </LinkBase> |
| 69 | + </li> |
| 70 | + <li v-if="forks && forksLink"> |
| 71 | + <LinkBase :to="forksLink" classicon="i-lucide:git-fork"> |
| 72 | + {{ compactNumberFormatter.format(forks) }} |
| 73 | + </LinkBase> |
| 74 | + </li> |
| 75 | + <li class="basis-full sm:hidden" /> |
| 76 | + <li v-if="homepageUrl"> |
| 77 | + <LinkBase :to="homepageUrl" classicon="i-lucide:link"> |
| 78 | + {{ $t('package.links.homepage') }} |
| 79 | + </LinkBase> |
| 80 | + </li> |
| 81 | + <li v-if="displayVersion?.bugs?.url"> |
| 82 | + <LinkBase :to="displayVersion.bugs.url" classicon="i-lucide:circle-alert"> |
| 83 | + {{ $t('package.links.issues') }} |
| 84 | + </LinkBase> |
| 85 | + </li> |
| 86 | + <li> |
| 87 | + <LinkBase |
| 88 | + :to="`https://www.npmjs.com/package/${pkg.name}`" |
| 89 | + :title="$t('common.view_on.npm')" |
| 90 | + classicon="i-simple-icons:npm" |
| 91 | + > |
| 92 | + npm |
| 93 | + </LinkBase> |
| 94 | + </li> |
| 95 | + <li v-if="jsrInfo?.exists && jsrInfo.url"> |
| 96 | + <LinkBase :to="jsrInfo.url" :title="$t('badges.jsr.title')" classicon="i-simple-icons:jsr"> |
| 97 | + {{ $t('package.links.jsr') }} |
| 98 | + </LinkBase> |
| 99 | + </li> |
| 100 | + <li v-if="fundingUrl"> |
| 101 | + <LinkBase :to="fundingUrl" classicon="i-lucide:heart"> |
| 102 | + {{ $t('package.links.fund') }} |
| 103 | + </LinkBase> |
| 104 | + </li> |
| 105 | + </ul> |
| 106 | +</template> |
0 commit comments