From 71f82ed717680dafa767005a56be9896c85141f3 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Oct 2025 13:51:49 -0500 Subject: [PATCH] Add external provider icons with favicons --- package-lock.json | 37 --------------- package.json | 2 - src/App.tsx | 1 + src/components/AppProvider.tsx | 1 + src/components/DeployDialog.tsx | 60 +++++++++++++++++++++--- src/components/ExternalFavicon.tsx | 57 +++++++++++++++++++++++ src/contexts/AppContext.ts | 2 + src/hooks/useAIProjectId.test.ts | 1 + src/hooks/useGit.test.ts | 1 + src/lib/faviconUrl.ts | 40 ++++++++++++++++ src/pages/AISettings.tsx | 50 ++++++++++++-------- src/pages/DeploySettings.tsx | 74 +++++++++++++++++++++++++----- src/pages/GitSettings.tsx | 31 +++++++------ src/pages/SystemSettings.tsx | 31 +++++++++++++ src/test/TestApp.tsx | 1 + 15 files changed, 300 insertions(+), 89 deletions(-) create mode 100644 src/components/ExternalFavicon.tsx create mode 100644 src/lib/faviconUrl.ts diff --git a/package-lock.json b/package-lock.json index 080cad68..9673d9dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,6 @@ "@fontsource-variable/inter": "^5.2.6", "@getalby/sdk": "^6.0.1", "@hookform/resolvers": "^3.9.0", - "@icons-pack/react-simple-icons": "^13.8.0", "@isomorphic-git/lightning-fs": "^4.6.2", "@mozilla/readability": "^0.6.0", "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.5", @@ -47,7 +46,6 @@ "@radix-ui/react-toggle-group": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.4", "@std/encoding": "npm:@jsr/std__encoding@^1.0.10", - "@tabler/icons-react": "^3.35.0", "@tanstack/react-query": "^5.56.2", "@unhead/addons": "^2.0.10", "@unhead/react": "^2.0.10", @@ -1200,15 +1198,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@icons-pack/react-simple-icons": { - "version": "13.8.0", - "resolved": "https://registry.npmjs.org/@icons-pack/react-simple-icons/-/react-simple-icons-13.8.0.tgz", - "integrity": "sha512-iZrhL1fSklfCCVn68IYHaAoKfcby3RakUTn2tRPyHBkhr2tkYqeQbjJWf+NizIYBzKBn2IarDJXmTdXd6CuEfw==", - "license": "MIT", - "peerDependencies": { - "react": "^16.13 || ^17 || ^18 || ^19" - } - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -3488,32 +3477,6 @@ "@swc/counter": "^0.1.3" } }, - "node_modules/@tabler/icons": { - "version": "3.35.0", - "resolved": "https://registry.npmjs.org/@tabler/icons/-/icons-3.35.0.tgz", - "integrity": "sha512-yYXe+gJ56xlZFiXwV9zVoe3FWCGuZ/D7/G4ZIlDtGxSx5CGQK110wrnT29gUj52kEZoxqF7oURTk97GQxELOFQ==", - "license": "MIT", - "funding": { - "type": "github", - "url": "https://github.com/sponsors/codecalm" - } - }, - "node_modules/@tabler/icons-react": { - "version": "3.35.0", - "resolved": "https://registry.npmjs.org/@tabler/icons-react/-/icons-react-3.35.0.tgz", - "integrity": "sha512-XG7t2DYf3DyHT5jxFNp5xyLVbL4hMJYJhiSdHADzAjLRYfL7AnjlRfiHDHeXxkb2N103rEIvTsBRazxXtAUz2g==", - "license": "MIT", - "dependencies": { - "@tabler/icons": "3.35.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/codecalm" - }, - "peerDependencies": { - "react": ">= 16" - } - }, "node_modules/@tailwindcss/typography": { "version": "0.5.16", "resolved": "https://registry.npmjs.org/@tailwindcss/typography/-/typography-0.5.16.tgz", diff --git a/package.json b/package.json index 66a22cf7..bc546a2f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "@fontsource-variable/inter": "^5.2.6", "@getalby/sdk": "^6.0.1", "@hookform/resolvers": "^3.9.0", - "@icons-pack/react-simple-icons": "^13.8.0", "@isomorphic-git/lightning-fs": "^4.6.2", "@mozilla/readability": "^0.6.0", "@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.5", @@ -50,7 +49,6 @@ "@radix-ui/react-toggle-group": "^1.1.0", "@radix-ui/react-tooltip": "^1.1.4", "@std/encoding": "npm:@jsr/std__encoding@^1.0.10", - "@tabler/icons-react": "^3.35.0", "@tanstack/react-query": "^5.56.2", "@unhead/addons": "^2.0.10", "@unhead/react": "^2.0.10", diff --git a/src/App.tsx b/src/App.tsx index b5b4ae4a..87624070 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -46,6 +46,7 @@ const defaultConfig: AppConfig = { projectTemplate: "https://gitlab.com/soapbox-pub/mkstack.git", esmUrl: "https://esm.shakespeare.diy", corsProxy: "https://proxy.shakespeare.diy/?url={href}", + faviconUrl: "https://external-content.duckduckgo.com/ip3/{hostname}.ico", previewDomain: "local-shakespeare.dev", showcaseEnabled: true, showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc", diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index c5db5659..b3c20b2e 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -21,6 +21,7 @@ const AppConfigSchema = z.object({ projectTemplate: z.string().url(), esmUrl: z.string().url(), corsProxy: z.string().url(), + faviconUrl: z.string().url(), previewDomain: z.string().min(1), language: z.string(), showcaseEnabled: z.boolean(), diff --git a/src/components/DeployDialog.tsx b/src/components/DeployDialog.tsx index 8e56ffd2..b7415c2f 100644 --- a/src/components/DeployDialog.tsx +++ b/src/components/DeployDialog.tsx @@ -1,7 +1,7 @@ import { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Rocket, ExternalLink, AlertCircle } from 'lucide-react'; -import { SiNetlify, SiVercel } from '@icons-pack/react-simple-icons'; +import { ExternalFavicon } from '@/components/ExternalFavicon'; import { Dialog, DialogContent, @@ -28,12 +28,62 @@ import { useAppContext } from '@/hooks/useAppContext'; import { useNostr } from '@nostrify/react'; import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, DeployAdapter } from '@/lib/deploy'; import { Link } from 'react-router-dom'; -import type { ShakespeareDeployProvider, NetlifyProvider, VercelProvider } from '@/contexts/DeploySettingsContext'; +import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider } from '@/contexts/DeploySettingsContext'; import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm'; import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm'; import { VercelDeployForm } from '@/components/deploy/VercelDeployForm'; import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm'; +/** + * Helper function to get provider URL for favicon + */ +function getProviderUrl(provider: DeployProvider): string | null { + switch (provider.type) { + case 'shakespeare': + if (provider.host) { + return `https://${provider.host}`; + } + return 'https://shakespeare.diy'; + + case 'netlify': + if (provider.baseURL) { + return provider.baseURL; + } + return 'https://netlify.com'; + + case 'vercel': + if (provider.baseURL) { + return provider.baseURL; + } + return 'https://vercel.com'; + + case 'nsite': + return null; + + default: + return null; + } +} + +/** + * Render provider icon using favicon or fallback + */ +function renderProviderIcon(provider: DeployProvider, size = 14) { + const url = getProviderUrl(provider); + + if (url) { + return ( + } + /> + ); + } + + return ; +} + interface DeployDialogProps { projectId: string; projectName: string; @@ -388,8 +438,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep {selectedProvider ? (
- {selectedProvider.id === 'netlify' && } - {selectedProvider.id === 'vercel' && } + {renderProviderIcon(selectedProvider, 14)} {selectedProvider.name}
) : ( @@ -400,8 +449,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep {settings.providers.map((provider) => (
- {provider.id === 'netlify' && } - {provider.id === 'vercel' && } + {renderProviderIcon(provider, 14)} {provider.name}
diff --git a/src/components/ExternalFavicon.tsx b/src/components/ExternalFavicon.tsx new file mode 100644 index 00000000..1175d709 --- /dev/null +++ b/src/components/ExternalFavicon.tsx @@ -0,0 +1,57 @@ +import { useAppContext } from '@/hooks/useAppContext'; +import { faviconUrl, normalizeUrl } from '@/lib/faviconUrl'; +import { ReactNode } from 'react'; + +interface ExternalFaviconProps { + /** The URL to fetch the favicon for */ + url: string; + /** Size of the favicon in pixels */ + size?: number; + /** Fallback element to display if favicon fails to load */ + fallback?: ReactNode; + /** Additional CSS classes */ + className?: string; +} + +/** + * ExternalFavicon component that fetches and displays a favicon for a given URL + * using the configurable favicon service from app settings. + */ +export function ExternalFavicon({ + url, + size = 16, + fallback, + className = '', +}: ExternalFaviconProps) { + const { config } = useAppContext(); + + // Normalize the URL to ensure it has a protocol + const normalizedUrl = normalizeUrl(url); + + // Generate the favicon URL using the configured template + const faviconSrc = faviconUrl(config.faviconUrl, normalizedUrl); + + return ( + + { + // Hide the image and show the fallback on error + e.currentTarget.style.display = 'none'; + const fallbackElement = e.currentTarget.nextElementSibling as HTMLElement; + if (fallbackElement) { + fallbackElement.style.display = 'inline-block'; + } + }} + /> + {fallback && ( + + {fallback} + + )} + + ); +} diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index af69b188..863746c4 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -13,6 +13,8 @@ export interface AppConfig { esmUrl: string; /** HTTP proxy used to bypass CORS for AI and Git operations */ corsProxy: string; + /** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */ + faviconUrl: string; /** Preview domain for iframe sandboxing (e.g., "local-shakespeare.dev") */ previewDomain: string; /** Selected language */ diff --git a/src/hooks/useAIProjectId.test.ts b/src/hooks/useAIProjectId.test.ts index f4adad88..81d26571 100644 --- a/src/hooks/useAIProjectId.test.ts +++ b/src/hooks/useAIProjectId.test.ts @@ -45,6 +45,7 @@ describe('useAIProjectId', () => { projectTemplate: 'https://github.com/example/template', esmUrl: 'https://esm.sh', corsProxy: 'https://proxy.example.com/{href}', + faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', previewDomain: 'local-shakespeare.dev', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', diff --git a/src/hooks/useGit.test.ts b/src/hooks/useGit.test.ts index 185a8c25..2717dae7 100644 --- a/src/hooks/useGit.test.ts +++ b/src/hooks/useGit.test.ts @@ -37,6 +37,7 @@ function createWrapper(corsProxy: string) { projectTemplate: 'https://gitlab.com/soapbox-pub/mkstack.git', esmUrl: 'https://esm.test', corsProxy, + faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', previewDomain: 'local-test.dev', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', diff --git a/src/lib/faviconUrl.ts b/src/lib/faviconUrl.ts new file mode 100644 index 00000000..666738d6 --- /dev/null +++ b/src/lib/faviconUrl.ts @@ -0,0 +1,40 @@ +import UriTemplate from 'uri-templates'; + +/** + * Generate a favicon URL from a template and input URL + * @param template - URL template with placeholders like {hostname}, {origin}, etc. + * @param url - The URL to extract parts from + * @returns The hydrated favicon URL + */ +export function faviconUrl(template: string, url: string | URL): string { + const u = new URL(url); + + return UriTemplate(template).fill({ + href: u.href, + origin: u.origin, + protocol: u.protocol, + username: u.username, + password: u.password, + host: u.host, + hostname: u.hostname, + port: u.port, + pathname: u.pathname, + hash: u.hash, + search: u.search, + }); +} + +/** + * Normalize a URL string to ensure it has a protocol + * @param url - The URL string to normalize + * @returns A fully-qualified URL string + */ +export function normalizeUrl(url: string): string { + // If it already has a protocol, return as-is + if (/^https?:\/\//i.test(url)) { + return url; + } + + // Add https:// prefix + return `https://${url}`; +} diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index 6f4dcdf5..271445f0 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -1,7 +1,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Check, Bot, ArrowLeft, Trash2, GripVertical } from 'lucide-react'; -import { SiOpenai, SiAnthropic, SiGoogle, SiX } from '@icons-pack/react-simple-icons'; import { DndContext, closestCenter, @@ -21,7 +20,6 @@ import { useSortable, } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; -import { IconMasksTheater } from '@tabler/icons-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { PasswordInput } from '@/components/ui/password-input'; @@ -37,21 +35,25 @@ import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useNavigate, Link } from 'react-router-dom'; import type { AIProvider } from '@/contexts/AISettingsContext'; import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets'; +import { ExternalFavicon } from '@/components/ExternalFavicon'; -function renderIcon(providerId: string, size = 16) { - switch (providerId) { - case 'shakespeare': - return ; - case 'openai': - return ; - case 'anthropic': - return ; - case 'google': - return ; - case 'xai': - return ; - default: - return ; +/** A few provider-specific icon hacks */ +function getProviderIconUrl(provider: { id: string; baseURL: string }): string { + if (provider.id === 'ollama' && provider.baseURL === 'http://localhost:11434/v1') { + return 'https://ollama.com/'; + } else if (provider.baseURL === 'https://generativelanguage.googleapis.com/v1beta/openai') { + return 'https://gemini.google.com/'; + } else if (provider.baseURL === 'https://api.z.ai/api/paas/v4') { + return 'https://docs.z.ai/'; + } + try { + // Strip .ai and .api subdomains for a better chance at finding a favicon + const urlObj = new URL(provider.baseURL); + urlObj.hostname = urlObj.hostname.replace(/^(ai\.|api\.)/, ''); + return urlObj.toString(); + } catch { + // Fallback to baseURL + return provider.baseURL; } } @@ -99,7 +101,15 @@ function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpe )} - {renderIcon(provider.id)} + {provider.baseURL ? ( + } + /> + ) : ( + + )} {preset?.name || provider.id} @@ -379,7 +389,11 @@ export function AISettings() {
- {renderIcon(preset.id)} + } + />
{preset.name}
{(preset.apiKeysURL && preset.id !== "routstr") && ( diff --git a/src/pages/DeploySettings.tsx b/src/pages/DeploySettings.tsx index 16ec372d..1ef5a5da 100644 --- a/src/pages/DeploySettings.tsx +++ b/src/pages/DeploySettings.tsx @@ -2,7 +2,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Rocket, ArrowLeft, Trash2, Check, GripVertical, ChevronDown } from 'lucide-react'; import { Checkbox } from '@/components/ui/checkbox'; -import { SiNetlify, SiVercel } from '@icons-pack/react-simple-icons'; import { DropdownMenu, DropdownMenuContent, @@ -28,7 +27,6 @@ import { useSortable, } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; -import { IconMasksTheater } from '@tabler/icons-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { PasswordInput } from '@/components/ui/password-input'; @@ -42,6 +40,8 @@ import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useIsMobile } from '@/hooks/useIsMobile'; import { useNavigate, Link } from 'react-router-dom'; import type { DeployProvider } from '@/contexts/DeploySettingsContext'; +import { ExternalFavicon } from '@/components/ExternalFavicon'; +import { normalizeUrl } from '@/lib/faviconUrl'; interface PresetProvider { id: string; @@ -96,7 +96,18 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
)} - {renderIcon(provider.id)} + {(() => { + const url = getProviderUrl(provider); + return url ? ( + } + /> + ) : ( + + ); + })()} {provider.name} @@ -272,16 +283,35 @@ function generateCustomProviderId(type: string): string { return `${type}-${randomSegment}`; } -function renderIcon(providerId: string, size = 16) { - switch (providerId) { +function getProviderUrl(provider: DeployProvider | PresetProvider): string | null { + switch (provider.type) { case 'shakespeare': - return ; + // For Shakespeare providers, check for custom host first, then use default + if ('host' in provider && provider.host) { + return normalizeUrl(provider.host); + } + return 'https://shakespeare.diy'; + case 'netlify': - return ; + // For Netlify providers, check for custom baseURL first, then use default + if ('baseURL' in provider && provider.baseURL) { + return provider.baseURL; + } + return 'https://netlify.com'; + case 'vercel': - return ; + // For Vercel providers, check for custom baseURL first, then use default + if ('baseURL' in provider && provider.baseURL) { + return provider.baseURL; + } + return 'https://vercel.com'; + + case 'nsite': + // nsite uses Rocket icon fallback + return null; + default: - return ; + return null; } } @@ -564,7 +594,18 @@ export function DeploySettings() {
- {renderIcon(preset.id)} + {(() => { + const url = getProviderUrl(preset); + return url ? ( + } + /> + ) : ( + + ); + })()}
{preset.name}
{preset.apiKeyURL && !isOAuthConfigured && ( @@ -607,7 +648,18 @@ export function DeploySettings() { ) : ( <> - {renderIcon(preset.id)} + {(() => { + const url = getProviderUrl(preset); + return url ? ( + } + /> + ) : ( + + ); + })()} Connect to {preset.name} diff --git a/src/pages/GitSettings.tsx b/src/pages/GitSettings.tsx index 2916195f..4b243e70 100644 --- a/src/pages/GitSettings.tsx +++ b/src/pages/GitSettings.tsx @@ -2,7 +2,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Check, GitBranch, ArrowLeft, Trash2, ChevronDown } from 'lucide-react'; import { Button } from '@/components/ui/button'; -import { SiGithub, SiGitlab } from '@icons-pack/react-simple-icons'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; @@ -20,6 +19,7 @@ import { useIsMobile } from '@/hooks/useIsMobile'; import { useNavigate } from 'react-router-dom'; import type { GitCredential } from '@/contexts/GitSettingsContext'; import { PasswordInput } from '@/components/ui/password-input'; +import { ExternalFavicon } from '@/components/ExternalFavicon'; interface PresetProvider { id: string; @@ -46,17 +46,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [ }, ]; -function renderIcon(providerId: string, size = 16) { - switch (providerId) { - case 'github': - return ; - case 'gitlab': - return ; - default: - return ; - } -} - export function GitSettings() { const { t } = useTranslation(); const { settings, addCredential, removeCredential, updateCredential, updateSettings } = useGitSettings(); @@ -170,7 +159,11 @@ export function GitSettings() {
- {preset && renderIcon(preset.id)} + } + /> {preset?.name || new URL(origin).hostname} @@ -233,7 +226,11 @@ export function GitSettings() {
- {renderIcon(preset.id)} + } + />
{preset.name}
{preset.tokenURL && (preset.id !== 'github' || !isOAuthConfigured) && ( @@ -265,7 +262,11 @@ export function GitSettings() { ) : ( <> - + } + /> Connect to GitHub diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index 56bd8fcf..d64f8953 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -18,6 +18,7 @@ export function SystemSettings() { const [projectTemplateInput, setProjectTemplateInput] = useState(config.projectTemplate); const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl); const [corsProxyInput, setCorsProxyInput] = useState(config.corsProxy); + const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl); const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain); const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator); @@ -119,6 +120,36 @@ export function SystemSettings() { + {/* Favicon URL Configuration */} + + + +

Favicon URL

+
+ +
+ { + const value = e.target.value; + setFaviconUrlInput(value); + updateConfig((current) => ({ + ...current, + faviconUrl: value, + })); + }} + /> +

+ URL template for fetching favicons. Available variables: {'{hostname}'}, {'{origin}'}, {'{href}'}, {'{protocol}'}, {'{pathname}'} +

+
+
+
+
+ {/* JavaScript CDN Configuration */} diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx index 83e3920f..f330dcd9 100644 --- a/src/test/TestApp.tsx +++ b/src/test/TestApp.tsx @@ -33,6 +33,7 @@ export function TestApp({ children }: TestAppProps) { projectTemplate: 'https://gitlab.com/soapbox-pub/mkstack.git', esmUrl: 'https://esm.shakespeare.diy', corsProxy: 'https://proxy.shakespeare.diy/?url={href}', + faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico', previewDomain: 'local-shakespeare.dev', language: 'en', showcaseEnabled: true,