story-research-zapwall/lib/presentationParsing.ts
2026-01-06 08:10:43 +01:00

55 lines
2.1 KiB
TypeScript

import type { Article } from '@/types/nostr'
/**
* Extract presentation data from article content
* Supports multiple formats:
* 1. Old format: "${presentation}\n\n---\n\nDescription du contenu :\n${contentDescription}"
* 2. New format (content only): "Nouveau profil publié sur zapwall.fr\n<url>\n<photo>\nPrésentation personnelle : <presentation>\nDescription de votre contenu : <description>\nAdresse Bitcoin mainnet (pour le sponsoring) : <adresse>"
* 3. New format (with JSON in tag): JSON metadata is stored in the 'json' tag, not in content
*
* Note: For new notes, the JSON metadata is stored in the 'json' tag.
* This function extracts from content for backward compatibility only.
* The main extraction should use extractTagsFromEvent to get json from 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 && newFormatMatch[1] && descriptionMatch[1]) {
return {
presentation: newFormatMatch[1].trim(),
contentDescription: descriptionMatch[1].trim(),
}
}
// Note: JSON metadata is now stored in tags, not in content
// This function extracts from content for backward compatibility only
// The main extraction should use extractTagsFromEvent to get json from tags
// 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,
}
}