mirror of
https://github.com/PrimalHQ/primal-web-app.git
synced 2024-09-29 08:21:15 +00:00
Add hashtages to tags when creating a new Note
This commit is contained in:
parent
110fb06e53
commit
87cb1e08b5
@ -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]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user