Merge branch 'r-tags' into 'main'

Add r-tags to statuses

See merge request soapbox-pub/ditto!297
This commit is contained in:
Alex Gleason 2024-05-22 02:33:27 +00:00
commit 4d9b4d9475
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,7 @@
import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
import ISO6391 from 'iso-639-1'; import ISO6391 from 'iso-639-1';
import 'linkify-plugin-hashtag';
import linkify from 'linkifyjs';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { z } from 'zod'; import { z } from 'zod';
@ -140,8 +142,13 @@ const createStatusController: AppController = async (c) => {
tags.push(['p', pubkey]); tags.push(['p', pubkey]);
} }
for (const match of content.matchAll(/#(\w+)/g)) { for (const link of linkify.find(data.status ?? '')) {
tags.push(['t', match[1]]); 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 const mediaUrls: string[] = media