File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -473,6 +473,24 @@ defineOgImageComponent('Package', {
473473 downloads : () => (downloads .value ? formatNumber (downloads .value .downloads ) : ' ' ),
474474 license : () => pkg .value ?.license ?? ' ' ,
475475})
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+ }
476494 </script >
477495
478496<template >
@@ -1226,6 +1244,7 @@ defineOgImageComponent('Package', {
12261244 v-if =" readmeData?.html"
12271245 class =" readme-content prose prose-invert max-w-[70ch]"
12281246 v-html =" readmeData.html"
1247+ @click =" handleClick"
12291248 />
12301249 <p v-else class =" text-fg-subtle italic" >
12311250 {{ $t('package.readme.no_readme') }}
You can’t perform that action at this time.
0 commit comments