import type { Profile } from '../types' import { getAvatarUrl } from '../lib/api' export async function renderProfile( did: string, profile: Profile, handle: string, webUrl?: string ): Promise { const avatarUrl = await getAvatarUrl(did, profile) const displayName = profile.value.displayName || handle || 'Unknown' const description = profile.value.description || '' // Build profile link (e.g., https://bsky.app/profile/did:plc:xxx) const profileLink = webUrl ? `${webUrl}/profile/${did}` : null const handleHtml = profileLink ? `@${escapeHtml(handle)}` : `@${escapeHtml(handle)}` const avatarHtml = avatarUrl ? `${escapeHtml(displayName)}` : `
` return `
${avatarHtml}

${escapeHtml(displayName)}

${handleHtml}

${description ? `

${escapeHtml(description)}

` : ''}
` } export function mountProfile(container: HTMLElement, html: string): void { container.innerHTML = html } function escapeHtml(text: string): string { return text .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, ''') }