import type { Article } from '@/types/nostr' /** * Extract presentation data from article content * Supports two formats: * 1. Old format: "${presentation}\n\n---\n\nDescription du contenu :\n${contentDescription}" * 2. New format: "Nouveau profil publié sur zapwall.fr\n\n\nPrésentation personnelle : \nDescription de votre contenu : \nAdresse Bitcoin mainnet (pour le sponsoring) : \n\n---\n\n[Metadata JSON]\n" * The profile JSON is stored in the [Metadata JSON] section of the content, not in tags */ export function extractPresentationData(presentation: Article): { presentation: string contentDescription: string } { const content = presentation.content // Try new format first const newFormatMatch = content.match(/Présentation personnelle : (.+?)(?:\nDescription de votre contenu :|$)/s) const descriptionMatch = content.match(/Description de votre contenu : (.+?)(?:\nAdresse Bitcoin mainnet|$)/s) if (newFormatMatch && descriptionMatch) { return { presentation: newFormatMatch[1].trim(), contentDescription: descriptionMatch[1].trim(), } } // Try to extract from JSON metadata section const jsonMatch = content.match(/\[Metadata JSON\]\n(.+)$/s) if (jsonMatch) { try { const profileJson = JSON.parse(jsonMatch[1].trim()) if (profileJson.presentation && profileJson.contentDescription) { return { presentation: profileJson.presentation, contentDescription: profileJson.contentDescription, } } } catch (e) { // JSON parsing failed, continue with old format } } // Fallback to old format const separator = '\n\n---\n\nDescription du contenu :\n' const separatorIndex = content.indexOf(separator) if (separatorIndex === -1) { // Fallback: return content as presentation if separator not found return { presentation: content, contentDescription: '', } } const presentationText = content.substring(0, separatorIndex) const contentDescription = content.substring(separatorIndex + separator.length) return { presentation: presentationText, contentDescription, } }