import { SembleCard, SembleCollection } from "./types"; /** * Extract the collection ID from an AT Protocol URI * Example: at://did:plc:xxx/network.cosmik.collection/3m5a3ww5m4g2o -> 3m5a3ww5m4g2o */ export function extractCollectionId(uri: string): string { const parts = uri.split("/"); return parts[parts.length - 1]; } /** * Extract username from identifier (handle or DID) * Example: renderg.host -> renderg.host */ export function extractUsername(identifier: string): string { // If it's a DID, we'd need to resolve it, but for now we'll use the identifier as-is return identifier; } /** * Generate a Semble card link * Format: https://semble.so/url?id={cardUrl} */ export function generateCardLink(card: SembleCard): string { const cardUrl = card.value.url || ""; return cardUrl ? `https://semble.so/url?id=${encodeURIComponent(cardUrl)}` : ""; } /** * Generate a Semble collection link * Format: https://semble.so/profile/{username}/collections/{collectionId} */ export function generateCollectionLink(collection: SembleCollection, username: string): string { const collectionId = extractCollectionId(collection.uri); return `https://semble.so/profile/${username}/collections/${collectionId}`; } /** * Get the title of a card */ export function getCardTitle(card: SembleCard): string { return card.value.content?.metadata?.title || card.value.url || "Untitled Card"; } /** * Get the subtitle/description of a card */ export function getCardSubtitle(card: SembleCard): string { return card.value.content?.metadata?.description || card.value.url || "No description"; } /** * Format date for display */ export function formatDate(dateString: string): string { const date = new Date(dateString); return date.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric", }); }