import { mockDb } from '@/lib/mockDb' import { Link } from '@/i18n/routing' import { notFound } from 'next/navigation' import { Calendar, Tag, ArrowLeft } from 'lucide-react' import ListingCard from '@/components/ListingCard' import type { Metadata } from 'next' interface Props { params: Promise<{ locale: string; slug: string }> } export async function generateMetadata({ params }: Props): Promise { const { locale, slug } = await params const post = await mockDb.getBlogPostBySlug(slug) if (!post) return {} const title = locale === 'en' ? post.titleEn : locale === 'ru' ? post.titleRu : post.titleTr const content = locale === 'en' ? post.contentEn : locale === 'ru' ? post.contentRu : post.contentTr const description = content.substring(0, 150) const fullTitle = `${title} — Marmaris Local` return { title: fullTitle, description, openGraph: { title: fullTitle, description, type: 'article', ...(post.coverImage ? { images: [{ url: post.coverImage }] } : {}), }, twitter: { card: 'summary_large_image', title: fullTitle, description, }, } } // Lightweight safe Markdown to HTML parsing function function renderMarkdownToHtml(md: string): string { if (!md) return '' let html = md .replace(/&/g, '&') .replace(//g, '>') // Bold html = html.replace(/\*\*(.*?)\*\*/g, '$1') html = html.replace(/__(.*?)__/g, '$1') // Italic html = html.replace(/\*(.*?)\*/g, '$1') html = html.replace(/_(.*?)_/g, '$1') // Headings html = html.replace(/^### (.*?)$/gm, '

$1

') html = html.replace(/^## (.*?)$/gm, '

$1

') html = html.replace(/^# (.*?)$/gm, '

$1

') // Bullet Lists html = html.replace(/^\* (.*?)$/gm, '
  • $1
  • ') html = html.replace(/^- (.*?)$/gm, '
  • $1
  • ') // Links html = html.replace(/\[(.*?)\]\((.*?)\)/g, '$1') // Paragraphs const blocks = html.split(/\n\n+/) html = blocks.map(block => { const trimmed = block.trim() if (!trimmed) return '' if (trimmed.startsWith('${trimmed.replace(/\n/g, '
    ')}

    ` }).join('\n') return html } export default async function BlogPostDetailPage({ params }: Props) { const { locale, slug } = await params const post = await mockDb.getBlogPostBySlug(slug) if (!post || post.deletedAt) { notFound() } const title = locale === 'en' ? post.titleEn : locale === 'ru' ? post.titleRu : post.titleTr const content = locale === 'en' ? post.contentEn : locale === 'ru' ? post.contentRu : post.contentTr const htmlContent = renderMarkdownToHtml(content) // Fetch associated listings const relatedListings: any[] = [] if (post.relatedListingIds && post.relatedListingIds.length > 0) { for (const listingId of post.relatedListingIds) { const listing = await mockDb.getListingById(listingId) if (listing) { relatedListings.push(listing) } } } // schema.org Structured Data const jsonLd = { '@context': 'https://schema.org', '@type': 'Article', 'headline': title, 'image': post.coverImage || 'https://images.unsplash.com/photo-1504674900247-0877df9cc836?w=1200&auto=format&fit=crop&q=80', 'datePublished': post.publishedAt || post.createdAt, 'dateModified': post.updatedAt, 'author': { '@type': 'Organization', 'name': 'Marmaris Local', 'url': 'https://marmarislocal.com' }, 'publisher': { '@type': 'Organization', 'name': 'Marmaris Local', 'logo': { '@type': 'ImageObject', 'url': 'https://marmarislocal.com/logo.png' } }, 'description': content.substring(0, 150) } return ( <> {/* Schema.org Article Structured Data */}