Skip to content

Commit 4ba7123

Browse files
committed
feat: replace framework pkgs with random "n p m x" picks
Show 4 randomly-selected packages whose names contain the letters n, p, m, X, with the matching letter highlighted in bold + accent colour (one distinct colour per letter when no user accent is set). Selection algorithm: 1. Fetch top 500 popular packages from the Algolia search index (empty query, default popularity ranking). Algolia doesn't support filtering by name substring (and doesn't know about our social likes), so we filter these results down after the fact (not deprecated, >=10k downloads/30d, modified <2yrs). 2. For each letter (n, p, m, x) 1. Take 30 random candidates whose name contains that letter and check their social like count. 2. If there are candidates with >=5 community likes, keep only those; otherwise, keep all. 3. Randomly pick one remaining candidate. 4. If there are no remaining candidates, pick the hardcoded default for this letter (nuxt, pnpm, module-replacements, oxfmt). Results are cached for 1 hour via with SWR, so all users see the same picks for about an hour, and no user ever experiences a cache miss (and Algolia/constellation slowness).
1 parent 0fd5a7d commit 4ba7123

61 files changed

Lines changed: 307 additions & 72 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/pages/index.vue

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<script setup lang="ts">
2-
import { SHOWCASED_FRAMEWORKS } from '~/utils/frameworks'
2+
import type { NpmxPicksResponse } from '#shared/types/picks'
3+
4+
const { data: picksData } = useFetch<NpmxPicksResponse>('/api/picks')
5+
const { selectedAccentColor } = useAccentColor()
6+
7+
const PICK_COLORS = ['coral', 'amber', 'emerald', 'sky'] as const
8+
function pickLetterColor(index: number): string | undefined {
9+
if (selectedAccentColor.value) return undefined
10+
return `var(--swatch-${PICK_COLORS[index]})`
11+
}
312
413
const { model: searchQuery, flushUpdateUrlQuery } = useGlobalSearch()
514
const isSearchFocused = shallowRef(false)
@@ -108,17 +117,22 @@ defineOgImageComponent('Default', {
108117
</header>
109118

110119
<nav
111-
:aria-label="$t('nav.popular_packages')"
120+
v-if="picksData?.picks?.length"
121+
:aria-label="$t('nav.npmx_picks')"
112122
class="pt-4 pb-36 sm:pb-40 text-center motion-safe:animate-fade-in motion-safe:animate-fill-both max-w-xl mx-auto"
113123
style="animation-delay: 0.3s"
114124
>
115125
<ul class="flex flex-wrap items-center justify-center gap-x-6 gap-y-3 list-none m-0 p-0">
116-
<li v-for="framework in SHOWCASED_FRAMEWORKS" :key="framework.name">
117-
<LinkBase :to="packageRoute(framework.package)" class="gap-2 text-sm">
126+
<li v-for="(pick, i) in picksData?.picks" :key="pick.letter">
127+
<LinkBase :to="packageRoute(pick.name)" class="text-sm">
118128
<span
119-
class="home-tag-dot w-1 h-1 rounded-full bg-accent group-hover:bg-fg transition-colors duration-200"
120-
/>
121-
{{ framework.name }}
129+
>{{ pick.name.slice(0, pick.letterIndex)
130+
}}<span
131+
class="font-bold text-accent"
132+
:style="pickLetterColor(i) ? { color: pickLetterColor(i) } : undefined"
133+
>{{ pick.name[pick.letterIndex] }}</span
134+
>{{ pick.name.slice(pick.letterIndex + 1) }}</span
135+
>
122136
</LinkBase>
123137
</li>
124138
</ul>
@@ -132,13 +146,3 @@ defineOgImageComponent('Default', {
132146
</section>
133147
</main>
134148
</template>
135-
136-
<style scoped>
137-
/* Windows High Contrast Mode support */
138-
@media (forced-colors: active) {
139-
.home-tag-dot {
140-
forced-color-adjust: none;
141-
background-color: CanvasText;
142-
}
143-
}
144-
</style>

i18n/locales/ar.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"nav": {
6868
"main_navigation": "الصفحة الرئيسية",
69-
"popular_packages": "الحزم الشائعة",
7069
"settings": "الإعدادات",
7170
"compare": "مقارنة",
7271
"back": "عودة",

i18n/locales/az-AZ.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
},
4343
"nav": {
4444
"main_navigation": "Əsas",
45-
"popular_packages": "Populyar paketlər",
4645
"settings": "tənzimləmələr",
4746
"back": "geri"
4847
},

i18n/locales/bg-BG.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Главна",
69-
"popular_packages": "Популярни пакети",
7069
"settings": "настройки",
7170
"compare": "сравняване",
7271
"back": "назад",

i18n/locales/bn-IN.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
},
4444
"nav": {
4545
"main_navigation": "প্রধান",
46-
"popular_packages": "জনপ্রিয় প্যাকেজগুলি",
4746
"settings": "সেটিংস",
4847
"compare": "তুলনা করুন",
4948
"back": "পিছনে",

i18n/locales/cs-CZ.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Hlavní",
69-
"popular_packages": "Populární balíčky",
7069
"settings": "nastavení",
7170
"compare": "porovnat",
7271
"back": "zpět",

i18n/locales/de-DE.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Hauptnavigation",
69-
"popular_packages": "Beliebte Pakete",
7069
"settings": "Einstellungen",
7170
"compare": "Vergleichen",
7271
"back": "Zurück",

i18n/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Main",
69-
"popular_packages": "Popular packages",
69+
"npmx_picks": "npmx picks",
7070
"settings": "settings",
7171
"compare": "compare",
7272
"back": "back",

i18n/locales/es.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Principal",
69-
"popular_packages": "Paquetes populares",
7069
"settings": "configuración",
7170
"compare": "comparar",
7271
"back": "atrás",

i18n/locales/fr-FR.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"nav": {
6868
"main_navigation": "Barre de navigation",
69-
"popular_packages": "Paquets populaires",
69+
"npmx_picks": "Suggestions npmx",
7070
"settings": "paramètres",
7171
"compare": "comparer",
7272
"back": "Retour",

0 commit comments

Comments
 (0)