Let ngitWebUrl be configurable

This commit is contained in:
Alex Gleason committed 2025-12-23 01:21:56 -06:00
1 parent 43190b7a35
commit b82b4539d9
22 files changed
+194 -12

No files matched your search

+1
View File
@@ -133,6 +133,7 @@ const defaultConfig: AppConfig = {
esmUrl: "https://esm.sh",
corsProxy: "https://proxy.shakespeare.diy/?url={href}",
faviconUrl: "https://favicon.shakespeare.diy/?url={href}",
ngitWebUrl: "https://nostrhub.io/{naddr}",
previewDomain: "local-shakespeare.dev",
showcaseEnabled: true,
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
+1
View File
@@ -46,6 +46,7 @@ const AppConfigSchema = z.object({
esmUrl: z.string().url(),
corsProxy: z.string().url(),
faviconUrl: z.string().url(),
ngitWebUrl: z.string().url(),
previewDomain: z.string().min(1),
language: z.string(),
showcaseEnabled: z.boolean(),
+4
View File
@@ -35,6 +35,7 @@ describe('SentryProvider', () => {
esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}',
faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev',
showcaseEnabled: false,
showcaseModerator: '',
@@ -75,6 +76,7 @@ describe('SentryProvider', () => {
esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}',
faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev',
showcaseEnabled: false,
showcaseModerator: '',
@@ -116,6 +118,7 @@ describe('SentryProvider', () => {
esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}',
faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev',
showcaseEnabled: false,
showcaseModerator: '',
@@ -160,6 +163,7 @@ describe('SentryProvider', () => {
esmUrl: 'https://esm.test',
corsProxy: 'https://proxy.test/{href}',
faviconUrl: 'https://favicon.test/{href}',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'test.dev',
showcaseEnabled: false,
showcaseModerator: '',
+5 -3
View File
@@ -15,9 +15,11 @@ import { useGitStatus } from '@/hooks/useGitStatus';
import { useGitSettings } from '@/hooks/useGitSettings';
import { useGit } from '@/hooks/useGit';
import { useFSPaths } from '@/hooks/useFSPaths';
import { useAppContext } from '@/hooks/useAppContext';
import type { StepProps } from '../types';
import { cn } from '@/lib/utils';
import { NostrURI } from '@/lib/NostrURI';
import { ngitWebUrl } from '@/lib/ngitWebUrl';
export function SyncStep({ projectId }: StepProps) {
const [isSyncing, setIsSyncing] = useState(false);
@@ -29,6 +31,7 @@ export function SyncStep({ projectId }: StepProps) {
const { settings } = useGitSettings();
const { git } = useGit();
const { projectsPath } = useFSPaths();
const { config } = useAppContext();
const originRemote = gitStatus?.remotes.find(r => r.name === 'origin');
@@ -109,10 +112,9 @@ export function SyncStep({ projectId }: StepProps) {
// For HTTPS URLs, open directly
externalUrl = originRemote.url;
} else if (originRemote.url.startsWith('nostr://')) {
// For Nostr URLs, parse and convert to naddr, then link to nostrhub.io
// For Nostr URLs, parse and generate URL using the configured template
const nostrUri = await NostrURI.parse(originRemote.url);
const naddr = nostrUri.toNaddr();
externalUrl = `https://nostrhub.io/${naddr}`;
externalUrl = ngitWebUrl(config.ngitWebUrl, nostrUri);
} else {
// Unsupported URL type
return;
+2
View File
@@ -40,6 +40,8 @@ export interface AppConfig {
corsProxy: string;
/** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */
faviconUrl: string;
/** Nostr Git web URL template (e.g., "https://nostrhub.io/{naddr}") */
ngitWebUrl: string;
/** Preview domain for iframe sandboxing (e.g., "local-shakespeare.dev") */
previewDomain: string;
/** Selected language */
+2
View File
@@ -64,6 +64,7 @@ describe('useGenerateProjectInfo', () => {
esmUrl: 'https://esm.sh',
corsProxy: 'https://proxy.example.com/{href}',
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev',
showcaseEnabled: true,
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
@@ -224,6 +225,7 @@ describe('useGenerateProjectInfo', () => {
esmUrl: 'https://esm.sh',
corsProxy: 'https://proxy.example.com/{href}',
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev',
showcaseEnabled: true,
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
+1
View File
@@ -41,6 +41,7 @@ function createWrapper(corsProxy: string) {
esmUrl: 'https://esm.test',
corsProxy,
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-test.dev',
showcaseEnabled: true,
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
+3 -3
View File
@@ -127,7 +127,7 @@ describe('NostrURI', () => {
identifier: testIdentifier,
});
const naddr = uri.toNaddr(30617);
const naddr = uri.toNaddr();
const decoded = nip19.decode(naddr);
expect(decoded.type).toBe('naddr');
@@ -147,7 +147,7 @@ describe('NostrURI', () => {
relay: testRelay,
});
const naddr = uri.toNaddr(30617);
const naddr = uri.toNaddr();
const decoded = nip19.decode(naddr);
expect(decoded.type).toBe('naddr');
@@ -272,7 +272,7 @@ describe('NostrURI', () => {
relay: testRelay,
});
const naddr = uri.toNaddr(30617);
const naddr = uri.toNaddr();
const result = NostrURI.fromNaddr(naddr);
expect(result.pubkey).toBe(uri.pubkey);
+3 -4
View File
@@ -171,23 +171,22 @@ export class NostrURI {
/**
* Convert to an naddr (NIP-19 addressable event identifier)
*
* @param kind - The event kind (default: 30617 for repository announcements)
* @returns An naddr string
*
* @example
* ```ts
* const uri = new NostrURI({ pubkey: 'abc...', identifier: 'my-repo' });
* const naddr = uri.toNaddr(30617);
* const naddr = uri.toNaddr();
* ```
*/
toNaddr(kind: number = 30617): string {
toNaddr(): string {
const data: {
kind: number;
pubkey: string;
identifier: string;
relays?: string[];
} = {
kind,
kind: 30617,
pubkey: this.pubkey,
identifier: this.identifier,
};
+1
View File
@@ -44,6 +44,7 @@ const testConfig: AppConfig = {
esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev',
language: 'en',
showcaseEnabled: true,
+1 -1
View File
@@ -1299,7 +1299,7 @@ export class Git {
await this.setConfig({
dir: options.dir,
path: 'nostr.repo',
value: nostrURI.toNaddr(30617),
value: nostrURI.toNaddr(),
});
// Validate the cloned repository against the expected state
+74
View File
@@ -0,0 +1,74 @@
import { describe, it, expect } from 'vitest';
import { ngitWebUrl } from './ngitWebUrl';
import { NostrURI } from './NostrURI';
describe('ngitWebUrl', () => {
it('generates URL with naddr placeholder', () => {
const template = 'https://nostrhub.io/{naddr}';
const pubkey = 'a'.repeat(64); // 64-character hex pubkey
const identifier = 'my-repo';
const nostrURI = new NostrURI({ pubkey, identifier });
const result = ngitWebUrl(template, nostrURI);
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
});
it('generates URL with npub placeholder', () => {
const template = 'https://example.com/{npub}';
const pubkey = 'a'.repeat(64);
const identifier = 'my-repo';
const nostrURI = new NostrURI({ pubkey, identifier });
const result = ngitWebUrl(template, nostrURI);
expect(result).toMatch(/^https:\/\/example\.com\/npub1/);
});
it('generates URL with pubkey placeholder', () => {
const template = 'https://example.com/{pubkey}';
const pubkey = 'a'.repeat(64);
const identifier = 'my-repo';
const nostrURI = new NostrURI({ pubkey, identifier });
const result = ngitWebUrl(template, nostrURI);
expect(result).toBe(`https://example.com/${pubkey}`);
});
it('generates URL with identifier placeholder', () => {
const template = 'https://example.com/{identifier}';
const pubkey = 'a'.repeat(64);
const identifier = 'my-repo';
const nostrURI = new NostrURI({ pubkey, identifier });
const result = ngitWebUrl(template, nostrURI);
expect(result).toBe('https://example.com/my-repo');
});
it('generates URL with multiple placeholders', () => {
const template = 'https://example.com/{npub}/{identifier}';
const pubkey = 'a'.repeat(64);
const identifier = 'my-repo';
const nostrURI = new NostrURI({ pubkey, identifier });
const result = ngitWebUrl(template, nostrURI);
expect(result).toMatch(/^https:\/\/example\.com\/npub1[^/]+\/my-repo$/);
});
it('includes relay in naddr when provided', () => {
const template = 'https://nostrhub.io/{naddr}';
const pubkey = 'a'.repeat(64);
const identifier = 'my-repo';
const relay = 'wss://relay.example.com/';
const nostrURI = new NostrURI({ pubkey, identifier, relay });
const result = ngitWebUrl(template, nostrURI);
// The naddr should be longer when it includes relay information
expect(result).toMatch(/^https:\/\/nostrhub\.io\/naddr1/);
expect(result.length).toBeGreaterThan(50);
});
});
+21
View File
@@ -0,0 +1,21 @@
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,
});
}
+1
View File
@@ -31,6 +31,7 @@ const testConfig: AppConfig = {
esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev',
language: 'en',
showcaseEnabled: true,
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "Clear Cache Failed",
"faviconUrl": "Favicon URL",
"faviconUrlDescription": "URL template for fetching favicons. Available variables: {hostname}, {origin}, {href}, {protocol}, {pathname}",
"ngitWebUrl": "Nostr Git Web URL",
"ngitWebUrlDescription": "URL template for Nostr Git repositories. Available variables: {naddr}, {npub}, {pubkey}, {identifier}",
"showcase": "Showcase",
"showcaseEnabled": "Showcase Enabled",
"showcaseEnabledDescription": "Display the app showcase section on the home page",
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "Share Cache Ya Gaza",
"faviconUrl": "URL na Favicon",
"faviconUrlDescription": "Samfurin URL don ɗaukar favicons. Masu canji da ake samu: {hostname}, {origin}, {href}, {protocol}, {pathname}",
"ngitWebUrl": "URL na Nostr Git Web",
"ngitWebUrlDescription": "Samfurin URL don ma'ajiyar Nostr Git. Masu canji da ake samu: {naddr}, {npub}, {pubkey}, {identifier}",
"showcase": "Nuni",
"showcaseEnabled": "An Kunna Nuni",
"showcaseEnabledDescription": "Nuna sashen nuni na aikace-aikace a shafin gida",
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "Nhicha Cache Dara",
"faviconUrl": "URL Favicon",
"faviconUrlDescription": "Ụdịdị URL maka ịnweta favicon. Mgbanwe dị: {hostname}, {origin}, {href}, {protocol}, {pathname}",
"ngitWebUrl": "URL Weebụ Nostr Git",
"ngitWebUrlDescription": "Ụdịdị URL maka ebe nchekwa Nostr Git. Mgbanwe dị: {naddr}, {npub}, {pubkey}, {identifier}",
"showcase": "Ngosipụta",
"showcaseEnabled": "Ngosipụta Emechara",
"showcaseEnabledDescription": "Gosipụta ngalaba ngosipụta ngwa na ibe ụlọ",
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "Limpeza de Cache Falhou",
"faviconUrl": "URL do Favicon",
"faviconUrlDescription": "Modelo de URL para buscar favicons. Variáveis disponíveis: {hostname}, {origin}, {href}, {protocol}, {pathname}",
"ngitWebUrl": "URL Web do Nostr Git",
"ngitWebUrlDescription": "Modelo de URL para repositórios Nostr Git. Variáveis disponíveis: {naddr}, {npub}, {pubkey}, {identifier}",
"showcase": "Vitrine",
"showcaseEnabled": "Vitrine Ativada",
"showcaseEnabledDescription": "Exibir a seção de vitrine de aplicativos na página inicial",
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "Ninu Cache Kuna",
"faviconUrl": "URL Favicon",
"faviconUrlDescription": "Awoṣe URL fun gbigba awọn favicon. Awọn oniyipada to wa: {hostname}, {origin}, {href}, {protocol}, {pathname}",
"ngitWebUrl": "URL Wẹẹbu Nostr Git",
"ngitWebUrlDescription": "Awoṣe URL fun awọn ibi ipamọ Nostr Git. Awọn oniyipada to wa: {naddr}, {npub}, {pubkey}, {identifier}",
"showcase": "Ifihan",
"showcaseEnabled": "Ifihan Ṣiṣẹ",
"showcaseEnabledDescription": "Ṣafihan apakan ifihan ohun elo lori oju-iwe ile",
+2
View File
@@ -46,6 +46,8 @@
"serviceWorkerClearCacheFailed": "清除缓存失败",
"faviconUrl": "Favicon URL",
"faviconUrlDescription": "获取favicon的URL模板。可用变量:{hostname}、{origin}、{href}、{protocol}、{pathname}",
"ngitWebUrl": "Nostr Git 网址",
"ngitWebUrlDescription": "Nostr Git 仓库的 URL 模板。可用变量:{naddr}、{npub}、{pubkey}、{identifier}",
"showcase": "展示",
"showcaseEnabled": "启用展示",
"showcaseEnabledDescription": "在主页上显示应用展示部分",
+61 -1
View File
@@ -1,4 +1,4 @@
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon } from "lucide-react";
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Cog, Globe, Image, Code, Monitor, Award, Bug, FolderTree, Terminal as TerminalIcon, GitBranch } from "lucide-react";
import { useTranslation } from 'react-i18next';
import { useState, useEffect, useMemo } from "react";
import { Button } from "@/components/ui/button";
@@ -24,6 +24,7 @@ export function SystemSettings() {
const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl);
const [corsProxyInput, setCorsProxyInput] = useState(config.corsProxy);
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
const [ngitWebUrlInput, setNgitWebUrlInput] = useState(config.ngitWebUrl);
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
const [fsPathProjectsInput, setFsPathProjectsInput] = useState(config.fsPathProjects);
@@ -38,6 +39,7 @@ export function SystemSettings() {
esmUrl: config.esmUrl !== defaultConfig.esmUrl,
corsProxy: config.corsProxy !== defaultConfig.corsProxy,
faviconUrl: config.faviconUrl !== defaultConfig.faviconUrl,
ngitWebUrl: config.ngitWebUrl !== defaultConfig.ngitWebUrl,
previewDomain: config.previewDomain !== defaultConfig.previewDomain,
showcaseEnabled: config.showcaseEnabled !== defaultConfig.showcaseEnabled,
showcaseModerator: config.showcaseModerator !== defaultConfig.showcaseModerator,
@@ -77,6 +79,15 @@ export function SystemSettings() {
});
};
const restoreNgitWebUrl = () => {
const defaultValue = defaultConfig.ngitWebUrl;
setNgitWebUrlInput(defaultValue);
updateConfig((current) => {
const { ngitWebUrl, ...rest } = current;
return rest;
});
};
const restorePreviewDomain = () => {
const defaultValue = defaultConfig.previewDomain;
setPreviewDomainInput(defaultValue);
@@ -486,6 +497,55 @@ export function SystemSettings() {
</AccordionItem>
</Accordion>
{/* Nostr Git Web URL Configuration */}
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="ngit-web-url">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center gap-2">
<GitBranch className="h-4 w-4 text-muted-foreground" />
<h4 className="text-sm font-medium">{t('ngitWebUrl')}</h4>
{isModified.ngitWebUrl && (
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
)}
</div>
</AccordionTrigger>
<AccordionContent className="px-4 pb-4">
<div className="py-1 space-y-2">
<div className="flex gap-2">
<Input
id="ngit-web-url"
type="url"
placeholder="https://nostrhub.io/{naddr}"
value={ngitWebUrlInput}
onChange={(e) => {
const value = e.target.value;
setNgitWebUrlInput(value);
updateConfig((current) => ({
...current,
ngitWebUrl: value,
}));
}}
className="flex-1"
/>
{isModified.ngitWebUrl && (
<Button
variant="outline"
size="icon"
onClick={restoreNgitWebUrl}
title={t('restoreToDefault')}
>
<RotateCcw className="h-4 w-4" />
</Button>
)}
</div>
<p className="text-xs text-muted-foreground">
{t('ngitWebUrlDescription')}
</p>
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
{/* JavaScript CDN Configuration */}
<Accordion type="single" collapsible className="w-full">
<AccordionItem value="esm-url">
+1
View File
@@ -45,6 +45,7 @@ export function TestApp({ children }: TestAppProps) {
esmUrl: 'https://esm.shakespeare.diy',
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
ngitWebUrl: 'https://nostrhub.io/{naddr}',
previewDomain: 'local-shakespeare.dev',
language: 'en',
showcaseEnabled: true,