|
| 1 | +<script setup lang="ts"> |
| 2 | +import { formatNumber } from '#imports' |
| 3 | +
|
| 4 | +const route = useRoute('org-name') |
| 5 | +
|
| 6 | +const orgName = computed(() => route.params.name) |
| 7 | +
|
| 8 | +// Search for packages in this org's scope (@orgname/*) |
| 9 | +const searchQuery = computed(() => `@${orgName.value}`) |
| 10 | +
|
| 11 | +const { data: results, status, error } = useNpmSearch(searchQuery, { size: 250 }) |
| 12 | +
|
| 13 | +// Filter to only include packages that are actually in this scope |
| 14 | +// (search may return packages that just mention the org name) |
| 15 | +const scopedPackages = computed(() => { |
| 16 | + if (!results.value?.objects) return [] |
| 17 | + const scopePrefix = `@${orgName.value}/` |
| 18 | + return results.value.objects |
| 19 | + .filter(obj => obj.package.name.startsWith(scopePrefix)) |
| 20 | + .sort((a, b) => b.searchScore - a.searchScore) |
| 21 | +}) |
| 22 | +
|
| 23 | +const packageCount = computed(() => scopedPackages.value.length) |
| 24 | +
|
| 25 | +useSeoMeta({ |
| 26 | + title: () => `@${orgName.value} - npmx`, |
| 27 | + description: () => `npm packages published by the ${orgName.value} organization`, |
| 28 | +}) |
| 29 | +
|
| 30 | +defineOgImageComponent('Default', { |
| 31 | + title: () => `@${orgName.value}`, |
| 32 | + description: () => scopedPackages.value.length ? `${scopedPackages.value.length} packages` : 'npm organization', |
| 33 | +}) |
| 34 | +</script> |
| 35 | + |
| 36 | +<template> |
| 37 | + <main class="container py-8 sm:py-12"> |
| 38 | + <!-- Header --> |
| 39 | + <header class="mb-8 pb-8 border-b border-border"> |
| 40 | + <div class="flex items-center gap-4 mb-4"> |
| 41 | + <!-- Org avatar placeholder --> |
| 42 | + <div |
| 43 | + class="w-16 h-16 rounded-lg bg-bg-muted border border-border flex items-center justify-center" |
| 44 | + aria-hidden="true" |
| 45 | + > |
| 46 | + <span class="text-2xl text-fg-subtle font-mono">{{ orgName.charAt(0).toUpperCase() }}</span> |
| 47 | + </div> |
| 48 | + <div> |
| 49 | + <h1 class="font-mono text-2xl sm:text-3xl font-medium"> |
| 50 | + @{{ orgName }} |
| 51 | + </h1> |
| 52 | + <p |
| 53 | + v-if="status === 'success'" |
| 54 | + class="text-fg-muted text-sm mt-1" |
| 55 | + > |
| 56 | + {{ formatNumber(packageCount) }} public package{{ packageCount === 1 ? '' : 's' }} |
| 57 | + </p> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + |
| 61 | + <!-- Link to npmjs.com org page --> |
| 62 | + <nav aria-label="External links"> |
| 63 | + <a |
| 64 | + :href="`https://www.npmjs.com/org/${orgName}`" |
| 65 | + target="_blank" |
| 66 | + rel="noopener noreferrer" |
| 67 | + class="link-subtle font-mono text-sm inline-flex items-center gap-1.5" |
| 68 | + > |
| 69 | + <span class="i-carbon-cube w-4 h-4" /> |
| 70 | + view on npm |
| 71 | + </a> |
| 72 | + </nav> |
| 73 | + </header> |
| 74 | + |
| 75 | + <!-- Loading state --> |
| 76 | + <LoadingSpinner |
| 77 | + v-if="status === 'pending'" |
| 78 | + text="Loading packages..." |
| 79 | + /> |
| 80 | + |
| 81 | + <!-- Error state --> |
| 82 | + <div |
| 83 | + v-else-if="status === 'error'" |
| 84 | + role="alert" |
| 85 | + class="py-12 text-center" |
| 86 | + > |
| 87 | + <p class="text-fg-muted mb-4"> |
| 88 | + {{ error?.message ?? 'Failed to load organization packages' }} |
| 89 | + </p> |
| 90 | + <NuxtLink |
| 91 | + to="/" |
| 92 | + class="btn" |
| 93 | + > |
| 94 | + Go back home |
| 95 | + </NuxtLink> |
| 96 | + </div> |
| 97 | + |
| 98 | + <!-- Empty state --> |
| 99 | + <div |
| 100 | + v-else-if="packageCount === 0" |
| 101 | + class="py-12 text-center" |
| 102 | + > |
| 103 | + <p class="text-fg-muted font-mono"> |
| 104 | + No public packages found for <span class="text-fg">@{{ orgName }}</span> |
| 105 | + </p> |
| 106 | + <p class="text-fg-subtle text-sm mt-2"> |
| 107 | + This organization may not exist or has no public packages. |
| 108 | + </p> |
| 109 | + </div> |
| 110 | + |
| 111 | + <!-- Package list --> |
| 112 | + <section |
| 113 | + v-else-if="scopedPackages.length > 0" |
| 114 | + aria-label="Organization packages" |
| 115 | + > |
| 116 | + <h2 class="text-xs text-fg-subtle uppercase tracking-wider mb-4"> |
| 117 | + Packages |
| 118 | + </h2> |
| 119 | + |
| 120 | + <PackageList :results="scopedPackages" /> |
| 121 | + </section> |
| 122 | + </main> |
| 123 | +</template> |
0 commit comments