import type { Event } from 'nostr-tools' import { extractTagsFromEvent } from '../nostrTagSystem' import type { PresentationProfileData } from './profileJson' type ExtractedTags = ReturnType export function buildPresentationArticle(params: { id: string hash: string version: number index: number event: Event tags: ExtractedTags profileData: PresentationProfileData | null originalCategory: 'science-fiction' | 'scientific-research' | undefined }): import('@/types/nostr').AuthorPresentationArticle { const description = resolvePresentationDescription(params.profileData, params.tags) const contentDescription = sanitizePresentationContentDescription(resolvePresentationContentDescriptionRaw(params.profileData, params.tags)) const thumbnailUrl = resolvePresentationThumbnailUrl(params.profileData, params.tags) const mainnetAddress = resolvePresentationMainnetAddress(params.profileData, params.tags) const bannerUrl = resolvePresentationBannerUrl(params.profileData, params.tags) const title = resolvePresentationTitle(params.tags) const preview = resolvePresentationPreview(params.tags, params.event.content) return { id: params.id, hash: params.hash, version: params.version, index: params.index, pubkey: params.event.pubkey, title, preview, content: params.event.content, description, contentDescription, thumbnailUrl, createdAt: params.event.created_at, zapAmount: 0, paid: true, category: 'author-presentation', isPresentation: true, mainnetAddress, totalSponsoring: 0, originalCategory: params.originalCategory ?? 'science-fiction', ...(bannerUrl ? { bannerUrl } : {}), } } function resolvePresentationTitle(tags: ExtractedTags): string { return typeof tags.title === 'string' && tags.title.length > 0 ? tags.title : 'Présentation' } function resolvePresentationPreview(tags: ExtractedTags, content: string): string { if (typeof tags.preview === 'string' && tags.preview.length > 0) { return tags.preview } return content.substring(0, 200) } function resolvePresentationDescription(profileData: PresentationProfileData | null, tags: ExtractedTags): string { if (typeof profileData?.presentation === 'string') { return profileData.presentation } return typeof tags.description === 'string' ? tags.description : '' } function resolvePresentationContentDescriptionRaw(profileData: PresentationProfileData | null, tags: ExtractedTags): string { if (typeof profileData?.contentDescription === 'string') { return profileData.contentDescription } return typeof tags.description === 'string' ? tags.description : '' } function sanitizePresentationContentDescription(raw: string): string { return raw .split('\n') .filter((line) => !line.includes('Adresse Bitcoin mainnet (pour le sponsoring)')) .join('\n') .trim() } function resolvePresentationThumbnailUrl(profileData: PresentationProfileData | null, tags: ExtractedTags): string { if (typeof profileData?.pictureUrl === 'string') { return profileData.pictureUrl } return typeof tags.pictureUrl === 'string' ? tags.pictureUrl : '' } function resolvePresentationBannerUrl(profileData: PresentationProfileData | null, tags: ExtractedTags): string | undefined { if (typeof profileData?.pictureUrl === 'string' && profileData.pictureUrl.length > 0) { return profileData.pictureUrl } return typeof tags.pictureUrl === 'string' ? tags.pictureUrl : undefined } function resolvePresentationMainnetAddress(profileData: PresentationProfileData | null, tags: ExtractedTags): string { const fromProfile = profileData?.mainnetAddress if (typeof fromProfile === 'string') { return fromProfile } return typeof tags.mainnetAddress === 'string' ? tags.mainnetAddress : '' }