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