Link plain Nostr URIs
Not just explicit Markdown links
This commit is contained in:
parent
010eb3f291
commit
5f38355d5c
14
nostr.ts
14
nostr.ts
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user