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'
interface Props {
params: Promise<{ locale: string; slug: string }>
}
export async function generateMetadata({ params }: Props) {
const { slug } = await params
const post = await mockDb.getBlogPostBySlug(slug)
if (!post) return {}
return {
title: `${post.titleTr} — Marmaris Local`,
description: post.contentTr.substring(0, 150)
}
}
// 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, '')
html = html.replace(/^# (.*?)$/gm, '')
// 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 */}
{/* Back Link */}
GERİ DÖN
{/* Article Box */}
{post.coverImage && (
)}
{/* Meta */}
{post.publishedAt ? new Date(post.publishedAt).toLocaleDateString(locale === 'tr' ? 'tr-TR' : locale === 'ru' ? 'ru-RU' : 'en-US') : ''}
{post.tags.map((tag) => (
{tag}
))}
{/* Title */}
{title}
{/* Markdown Content */}
{/* Related Listings Section (Internal Linking) */}
{relatedListings.length > 0 && (
yazıda geçen mekanlar
{relatedListings.map((listing) => (
))}
)}
>
)
}