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