Link plain Nostr URIs

Not just explicit Markdown links
This commit is contained in:
Râu Cao 2024-10-28 12:26:54 +01:00
parent 010eb3f291
commit 5f38355d5c
Signed by: raucao
GPG Key ID: 37036C356E56CC51

View File

@ -107,15 +107,13 @@ export async function nostrUriToUrl(uri: string): Promise<string> {
}
export async function replaceNostrUris(markdown: string): Promise<string> {
const nostrUriRegex =
/\((nostr:|nprofile|naddr|nevent|nrelay|npub)[a-z0-9]+\)/g;
const nostrUriRegex = /(nostr:|nprofile|naddr|nevent|nrelay|npub)[a-z0-9]+/g;
const matches = markdown.match(nostrUriRegex);
if (!matches) return markdown;
for (const match of matches) {
const uri = match.slice(1, -1);
for (const uri of matches) {
const url = await nostrUriToUrl(uri);
markdown = markdown.replace(match, `(${url})`);
markdown = markdown.replace(uri, url);
}
return markdown;
@ -133,11 +131,7 @@ export async function verifyNip05Address(
if (res.status === 404 || !res.ok) return false;
const data = await res.json();
if (data.names && data.names[username] === pubkey) {
return true;
} else {
return false;
}
return data.names && data.names[username] === pubkey;
} catch (_e) {
return false;
}