[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: convert npmjs urls in readme with npmx (#281)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Mikołaj Misztal
Daniel Roe
and committed by
GitHub
7c1bbe92 c9edc5e8

+19
+19
app/pages/[...package].vue
··· 473 473 downloads: () => (downloads.value ? formatNumber(downloads.value.downloads) : ''), 474 474 license: () => pkg.value?.license ?? '', 475 475 }) 476 + 477 + // We're using only @click because it catches touch events and enter hits 478 + function handleClick(event: MouseEvent) { 479 + const target = (event?.target as HTMLElement | undefined)?.closest('a') 480 + if (!target) return 481 + 482 + const href = target.getAttribute('href') 483 + if (!href) return 484 + 485 + const match = href.match(/^(?:https?:\/\/)?(?:www\.)?npmjs\.(?:com|org)(\/.+)$/) 486 + if (!match || !match[1]) return 487 + 488 + const route = router.resolve(match[1]) 489 + if (route) { 490 + event.preventDefault() 491 + router.push(route) 492 + } 493 + } 476 494 </script> 477 495 478 496 <template> ··· 1226 1244 v-if="readmeData?.html" 1227 1245 class="readme-content prose prose-invert max-w-[70ch]" 1228 1246 v-html="readmeData.html" 1247 + @click="handleClick" 1229 1248 /> 1230 1249 <p v-else class="text-fg-subtle italic"> 1231 1250 {{ $t('package.readme.no_readme') }}