Skip to content

Commit 0a3f4af

Browse files
committed
feat: convert npmjs urls in readme with npmx
1 parent 484a888 commit 0a3f4af

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

server/utils/readme.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ export async function renderReadmeHtml(
399399
if (attribs.href && hasProtocol(attribs.href, { acceptRelative: true })) {
400400
attribs.rel = 'nofollow noreferrer noopener'
401401
attribs.target = '_blank'
402+
403+
// Replace npmjs.com|npmjs.org urls with npmx.dev
404+
const npmjsMatch = attribs.href.match(
405+
/^(?:https?:\/\/)?(?:www\.)?npmjs\.(?:com|org)\/(.+)/,
406+
)
407+
if (npmjsMatch) {
408+
attribs.href = `https://npmx.dev/${npmjsMatch[1]}`
409+
}
402410
}
403411
return { tagName, attribs }
404412
},

0 commit comments

Comments
 (0)