Add hashtages to tags when creating a new Note

This commit is contained in:
Bojan Mojsilovic 2023-07-14 17:48:06 +02:00
parent 110fb06e53
commit 87cb1e08b5

View File

@ -307,14 +307,24 @@ type NoteStore = {
}
export const referencesToTags = (value: string) => {
const regex =
const regexHashtag = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig;
const regexMention =
/\bnostr:((note|npub|nevent|nprofile)1\w+)\b|#\[(\d+)\]/g;
let hashtags: string[] = [];
let refs: string[] = [];
let tags: string[][] = [];
let match;
while((match = regex.exec(value)) !== null) {
// Parse hashtags to add to tags
while((match = regexHashtag.exec(value)) != null) {
hashtags.push(match[0]);
}
tags = hashtags.map(h => ['t', h.slice(2)]);
// Parse mentions to add to tags
while((match = regexMention.exec(value)) !== null) {
refs.push(match[0]);
}