Skip to content

Commit 0080660

Browse files
committed
fix route issue
1 parent fb7c214 commit 0080660

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/lib/nostr/media.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ describe('media helpers', () => {
210210
]);
211211
});
212212

213+
it('extracts nostr.com thread urls as quoted note references', () => {
214+
const id = 'a4edc4f203db0b64b75d5367efdb5e06e8370367ea27a20b2a01a79fb70c6711';
215+
const url = `https://nostr.com/thread/${id}`;
216+
217+
expect(extractQuotedNoteReferences(`look ${url}`)).toEqual([{ id, raw: url }]);
218+
expect(parseNoteText(`look ${url}`, [url])).toEqual([{ type: 'text', value: 'look' }]);
219+
});
220+
213221
it('keeps nevent route links intact so relay hints survive navigation', () => {
214222
const id = 'f'.repeat(64);
215223
const nevent = nip19.neventEncode({ id, relays: ['wss://relay.example'] });

src/lib/nostr/media.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const webUrlPattern = /https?:\/\/[^\s<>"']+/gi;
77
const bareDomainPattern = /(^|[\s([{"'])([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+(?:\/[^\s<>"']*)?)/gi;
88
const hashtagPattern = /(^|[\s([{"'])#([A-Za-z0-9_]{2,64})/g;
99
const nostrRefPattern = /(?:nostr:)?((?:npub|nprofile|note|nevent)1[023456789acdefghjklmnpqrstuvwxyz]+)/gi;
10+
const nostrThreadUrlPattern = /https?:\/\/(?:www\.)?nostr\.com\/thread\/([0-9a-f]{64})(?:[/?#][^\s<>"']*)?/gi;
1011
const indexedRefPattern = /#\[(\d+)]/g;
1112
const mentionPattern = /(^|[\s([{"'])(@([A-Za-z0-9_.-]{2,64})(?:\/([A-Za-z0-9:_-]{4,128}))?)/g;
1213

@@ -84,6 +85,13 @@ export function extractQuotedNoteReferences(content: string, tags: string[][] =
8485
if (id) refs.set(id, { id, raw: match[0] });
8586
}
8687

88+
nostrThreadUrlPattern.lastIndex = 0;
89+
while ((match = nostrThreadUrlPattern.exec(content))) {
90+
const raw = trimTrailingUrlPunctuation(match[0]);
91+
const id = match[1].toLowerCase();
92+
refs.set(id, { id, raw });
93+
}
94+
8795
indexedRefPattern.lastIndex = 0;
8896
while ((match = indexedRefPattern.exec(content))) {
8997
const tag = tags[Number(match[1])];

0 commit comments

Comments
 (0)