import React from 'react'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { ArrowLeft, ArrowRight, User, Calendar, Share2 } from 'lucide-react'; import { sanitizeHTML } from '../../../lib/sanitize'; import { prisma } from '../../../lib/prisma'; import BlogShareButtons from '../../../components/BlogShareButtons'; import { Metadata } from 'next'; interface Props { params: Promise<{ id: string }>; } // Style spécifique pour empêcher strictement la coupure des mots tout en justifiant le texte const noBreakStyle = ` #blog-content, #blog-content p, #blog-content li, #blog-content span, #blog-content strong { word-break: normal !important; overflow-wrap: break-word !important; hyphens: none !important; line-break: normal !important; text-align: justify !important; text-justify: inter-word !important; } /* Sécurité supplémentaire pour les navigateurs mobiles */ .prose * { word-break: normal !important; hyphens: none !important; } `; export async function generateMetadata({ params }: Props): Promise { const { id } = await params; const post = await prisma.blogPost.findFirst({ where: { OR: [{ id: id }, { slug: id }], publishedAt: { lte: new Date() }, status: 'PUBLISHED' } }); if (!post) return { title: 'Article non trouvé' }; return { title: post.metaTitle || post.title, description: post.metaDescription || post.excerpt, keywords: post.tags, openGraph: { title: post.metaTitle || post.title, description: post.metaDescription || post.excerpt, images: [post.imageUrl], type: 'article', } }; } export default async function BlogPostPage({ params }: Props) { const { id } = await params; const post = await prisma.blogPost.findFirst({ where: { OR: [{ id: id }, { slug: id }], publishedAt: { lte: new Date() }, status: 'PUBLISHED' } }); if (!post) { notFound(); } // Articles en rapport : par tags communs, sinon les plus récents let relatedPosts = await prisma.blogPost.findMany({ where: { status: 'PUBLISHED', publishedAt: { lte: new Date() }, id: { not: post.id }, tags: { hasSome: post.tags } }, take: 3, orderBy: { date: 'desc' } }); // Compléter avec les articles récents si nécessaire if (relatedPosts.length < 2) { const excludedIds = [post.id, ...relatedPosts.map(p => p.id)]; const additionalPosts = await prisma.blogPost.findMany({ where: { status: 'PUBLISHED', publishedAt: { lte: new Date() }, id: { notIn: excludedIds } }, take: 3 - relatedPosts.length, orderBy: { date: 'desc' } }); relatedPosts = [...relatedPosts, ...additionalPosts]; } return (
{/* Injection du style de force pour le texte */}