From 5de7366ff0799e6ad83d036e97db003f2076c132 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 May 2024 21:22:25 -0500 Subject: [PATCH 1/2] Add r-tags to statuses --- src/controllers/api/statuses.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 58526cb..7b21c2d 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,5 +1,6 @@ import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import ISO6391 from 'iso-639-1'; +import linkify from 'linkifyjs'; import { nip19 } from 'nostr-tools'; import { z } from 'zod'; @@ -144,6 +145,12 @@ const createStatusController: AppController = async (c) => { tags.push(['t', match[1]]); } + for (const link of linkify.find(data.status ?? '')) { + if (link.type === 'url' && link.href.startsWith('https://')) { + tags.push(['r', link.href]); + } + } + const mediaUrls: string[] = media .map(({ data }) => data.find(([name]) => name === 'url')?.[1]) .filter((url): url is string => Boolean(url)); From 1a66570b562c2ba5a6f01292fa76cffbc6c0b212 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 May 2024 21:30:26 -0500 Subject: [PATCH 2/2] Use linkify to parse hashtags when creating a status, too --- src/controllers/api/statuses.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 7b21c2d..d1df002 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,5 +1,6 @@ import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import ISO6391 from 'iso-639-1'; +import 'linkify-plugin-hashtag'; import linkify from 'linkifyjs'; import { nip19 } from 'nostr-tools'; import { z } from 'zod'; @@ -141,14 +142,13 @@ const createStatusController: AppController = async (c) => { tags.push(['p', pubkey]); } - for (const match of content.matchAll(/#(\w+)/g)) { - tags.push(['t', match[1]]); - } - for (const link of linkify.find(data.status ?? '')) { if (link.type === 'url' && link.href.startsWith('https://')) { tags.push(['r', link.href]); } + if (link.type === 'hashtag') { + tags.push(['t', link.href.replace(/^#/, '').toLowerCase()]); + } } const mediaUrls: string[] = media