From 605948267dafec9e1c434f3151e2436893935f08 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 3 Jun 2024 12:30:29 -0500 Subject: [PATCH] Render mentions as nip19, fix href --- src/utils/note.ts | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/utils/note.ts b/src/utils/note.ts index c10e3e9f..e182decf 100644 --- a/src/utils/note.ts +++ b/src/utils/note.ts @@ -1,7 +1,7 @@ import 'linkify-plugin-hashtag'; import linkifyStr from 'linkify-string'; import linkify from 'linkifyjs'; -import { nip19, nip21 } from 'nostr-tools'; +import { nip21 } from 'nostr-tools'; import { Conf } from '@/config.ts'; import { getUrlMediaType, isPermittedMediaType } from '@/utils/media.ts'; @@ -18,15 +18,10 @@ const linkifyOpts: linkify.Opts = { }, url: ({ content }) => { try { - const { decoded } = nip21.parse(content); - const pubkey = getDecodedPubkey(decoded); - if (pubkey) { - const name = pubkey.substring(0, 8); - const href = Conf.local(`/users/${pubkey}`); - return `@${name}`; - } else { - return ''; - } + const { value } = nip21.parse(content); + const name = value.substring(0, 8); + const href = Conf.local(`/@${value}`); + return `@${name}`; } catch { return `${content}`; } @@ -108,14 +103,4 @@ function isLinkURL(link: Link): boolean { return link.type === 'url'; } -/** Get pubkey from decoded bech32 entity, or undefined if not applicable. */ -function getDecodedPubkey(decoded: nip19.DecodeResult): string | undefined { - switch (decoded.type) { - case 'npub': - return decoded.data; - case 'nprofile': - return decoded.data.pubkey; - } -} - export { getMediaLinks, parseNoteContent, stripimeta };