-
-
Notifications
You must be signed in to change notification settings - Fork 424
refactor(ui): move package external links to component #2077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <script setup lang="ts"> | ||
| import type { IconClass } from '~/types' | ||
|
|
||
| const props = defineProps<{ | ||
| pkg: SlimPackument | ||
| jsrInfo?: JsrPackageInfo | ||
| }>() | ||
|
|
||
| const displayVersion = computed(() => props.pkg?.requestedVersion ?? null) | ||
| const { repositoryUrl } = useRepositoryUrl(displayVersion.value) | ||
| const { meta: repoMeta, repoRef, stars, starsLink, forks, forksLink } = useRepoMeta(repositoryUrl) | ||
| const compactNumberFormatter = useCompactNumberFormatter() | ||
|
|
||
| const homepageUrl = computed(() => { | ||
| const homepage = displayVersion.value?.homepage | ||
| if (!homepage) return null | ||
|
|
||
| // Don't show homepage if it's the same as the repository URL | ||
| if (repositoryUrl.value && areUrlsEquivalent(homepage, repositoryUrl.value)) { | ||
| return null | ||
| } | ||
|
|
||
| return homepage | ||
| }) | ||
|
|
||
| const fundingUrl = computed(() => { | ||
| let funding = displayVersion.value?.funding | ||
| if (Array.isArray(funding)) funding = funding[0] | ||
|
|
||
| if (!funding) return null | ||
|
|
||
| return typeof funding === 'string' ? funding : funding.url | ||
| }) | ||
|
|
||
| const PROVIDER_ICONS: Record<string, IconClass> = { | ||
| github: 'i-simple-icons:github', | ||
| gitlab: 'i-simple-icons:gitlab', | ||
| bitbucket: 'i-simple-icons:bitbucket', | ||
| codeberg: 'i-simple-icons:codeberg', | ||
| gitea: 'i-simple-icons:gitea', | ||
| forgejo: 'i-simple-icons:forgejo', | ||
| gitee: 'i-simple-icons:gitee', | ||
| sourcehut: 'i-simple-icons:sourcehut', | ||
| tangled: 'i-custom:tangled', | ||
| radicle: 'i-lucide:network', // Radicle is a P2P network, using network icon | ||
| } | ||
|
|
||
| const repoProviderIcon = computed((): IconClass => { | ||
| const provider = repoRef.value?.provider | ||
| if (!provider) return 'i-simple-icons:github' | ||
| return PROVIDER_ICONS[provider] ?? 'i-lucide:code' | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <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"> | ||
| <li v-if="repositoryUrl"> | ||
| <LinkBase :to="repositoryUrl" :classicon="repoProviderIcon"> | ||
| <span v-if="repoRef"> | ||
| {{ repoRef.owner }}<span class="opacity-50">/</span>{{ repoRef.repo }} | ||
| </span> | ||
| <span v-else>{{ $t('package.links.repo') }}</span> | ||
| </LinkBase> | ||
| </li> | ||
| <li v-if="repositoryUrl && repoMeta && starsLink"> | ||
| <LinkBase :to="starsLink" classicon="i-lucide:star"> | ||
| {{ compactNumberFormatter.format(stars) }} | ||
| </LinkBase> | ||
| </li> | ||
| <li v-if="forks && forksLink"> | ||
| <LinkBase :to="forksLink" classicon="i-lucide:git-fork"> | ||
| {{ compactNumberFormatter.format(forks) }} | ||
| </LinkBase> | ||
| </li> | ||
| <li class="basis-full sm:hidden" /> | ||
| <li v-if="homepageUrl"> | ||
| <LinkBase :to="homepageUrl" classicon="i-lucide:link"> | ||
| {{ $t('package.links.homepage') }} | ||
| </LinkBase> | ||
| </li> | ||
| <li v-if="displayVersion?.bugs?.url"> | ||
| <LinkBase :to="displayVersion.bugs.url" classicon="i-lucide:circle-alert"> | ||
| {{ $t('package.links.issues') }} | ||
| </LinkBase> | ||
| </li> | ||
| <li> | ||
| <LinkBase | ||
| :to="`https://www.npmjs.com/package/${pkg.name}`" | ||
| :title="$t('common.view_on.npm')" | ||
| classicon="i-simple-icons:npm" | ||
|
Comment on lines
+87
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
file="app/components/Link/Base.vue"
echo "== $file =="
sed -n '1,220p' "$file"
echo
echo "== title-related lines =="
rg -n -C2 '\btitle\b|v-bind="props"|<NuxtLink|<span' "$file"Repository: npmx-dev/npmx.dev Length of output: 5693 🏁 Script executed: # Verify ExternalLinks.vue uses title attribute in the mentioned lines
sed -n '85,100p' app/components/Package/ExternalLinks.vue | cat -nRepository: npmx-dev/npmx.dev Length of output: 632 Add The |
||
| > | ||
| npm | ||
| </LinkBase> | ||
| </li> | ||
| <li v-if="jsrInfo?.exists && jsrInfo.url"> | ||
| <LinkBase :to="jsrInfo.url" :title="$t('badges.jsr.title')" classicon="i-simple-icons:jsr"> | ||
| {{ $t('package.links.jsr') }} | ||
| </LinkBase> | ||
| </li> | ||
| <li v-if="fundingUrl"> | ||
| <LinkBase :to="fundingUrl" classicon="i-lucide:heart"> | ||
| {{ $t('package.links.fund') }} | ||
| </LinkBase> | ||
| </li> | ||
| </ul> | ||
| </template> | ||
Uh oh!
There was an error while loading. Please reload this page.