mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
22 lines
698 B
TypeScript
22 lines
698 B
TypeScript
import UriTemplate from 'uri-templates';
|
|
import { nip19 } from 'nostr-tools';
|
|
import { NostrURI } from './NostrURI';
|
|
|
|
/**
|
|
* Generate a Nostr Git web URL from a template and Nostr URI
|
|
* @param template - URL template with placeholders like {naddr}, {npub}, {pubkey}, {identifier}
|
|
* @param nostrURI - The Nostr URI containing pubkey, identifier, and optional relay
|
|
* @returns The hydrated web URL
|
|
*/
|
|
export function ngitWebUrl(template: string, nostrURI: NostrURI): string {
|
|
const naddr = nostrURI.toNaddr();
|
|
const npub = nip19.npubEncode(nostrURI.pubkey);
|
|
|
|
return UriTemplate(template).fill({
|
|
naddr,
|
|
npub,
|
|
pubkey: nostrURI.pubkey,
|
|
identifier: nostrURI.identifier,
|
|
});
|
|
}
|