feat: Implement Phase 2 features including blog, collections, saved listings, manifest, and api cron sync

This commit is contained in:
AyrisAI
2026-07-12 20:49:41 +03:00
parent 862544b5a1
commit f696d359b0
29 changed files with 3066 additions and 194 deletions
@@ -0,0 +1,58 @@
'use client'
import { useState, useEffect } from 'react'
import { Heart } from 'lucide-react'
interface Props {
listingId: string
saveLabel: string
savedLabel: string
}
export default function SaveButton({ listingId, saveLabel, savedLabel }: Props) {
const [isSaved, setIsSaved] = useState(false)
useEffect(() => {
try {
const stored = localStorage.getItem('savedListingIds')
if (stored) {
const ids = JSON.parse(stored) as string[]
setIsSaved(ids.includes(listingId))
}
} catch (e) {
console.error('Error reading localStorage:', e)
}
}, [listingId])
const toggleSave = () => {
try {
const stored = localStorage.getItem('savedListingIds')
let ids: string[] = stored ? JSON.parse(stored) : []
if (ids.includes(listingId)) {
ids = ids.filter(id => id !== listingId)
setIsSaved(false)
} else {
ids.push(listingId)
setIsSaved(true)
}
localStorage.setItem('savedListingIds', JSON.stringify(ids))
window.dispatchEvent(new Event('favorites-updated'))
} catch (err) {
console.error('Error writing localStorage:', err)
}
}
return (
<button
onClick={toggleSave}
className={`flex items-center justify-center gap-2 border font-bold text-xs py-3.5 px-4 rounded-xl transition ${
isSaved
? 'bg-bougainvillea/5 border-bougainvillea/20 text-bougainvillea'
: 'bg-paper border-pine/15 hover:bg-stone text-pine'
}`}
>
<Heart className={`w-4 h-4 ${isSaved ? 'fill-bougainvillea text-bougainvillea' : 'text-pine/70'}`} />
{isSaved ? savedLabel : saveLabel}
</button>
)
}
+146 -23
View File
@@ -5,12 +5,25 @@ import Footer from '@/components/Footer'
import ListingCard from '@/components/ListingCard'
import { notFound } from 'next/navigation'
import Image from 'next/image'
import { Phone, Globe, MapPin, Clock, Star, MessageSquare } from 'lucide-react'
import { Link } from '@/i18n/routing'
import { Phone, Globe, MapPin, Clock, Star, MessageSquare, Share2 } from 'lucide-react'
import SaveButton from './SaveButton'
interface DetailPageProps {
params: Promise<{ locale: string; category: string; slug: string }>
}
export async function generateMetadata({ params }: DetailPageProps) {
const { slug } = await params
const listing = await mockDb.getListingBySlug(slug)
if (!listing) return {}
return {
title: `${listing.nameTr} — Marmaris Local`,
description: listing.descriptionTr
}
}
export default async function ListingDetailPage({ params }: DetailPageProps) {
const { locale, category, slug } = await params
setRequestLocale(locale)
@@ -30,6 +43,16 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
.filter(l => l.id !== listing.id)
.slice(0, 3)
// Fetch newest 3 listings (excluding current)
const allListings = await mockDb.getListings()
const latestListings = allListings
.filter(l => l.id !== listing.id)
.slice(0, 3)
// Fetch Instagram Feed Cache
const instagramFeed = await mockDb.getInstagramFeedCacheByListingId(listing.id)
const instagramPosts = instagramFeed?.posts ? (instagramFeed.posts as any[]) : []
// Localized values
const name =
locale === 'ru'
@@ -46,22 +69,28 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
: listing.descriptionTr
const priceSymbols = '₺'.repeat(listing.priceRange)
const categorySlug = listing.category?.slug || 'isletme'
// Format WhatsApp Link
const getWhatsAppLink = (number: string) => {
// Clean spaces, parenthesis, plus sign
const cleanNum = number.replace(/\D/g, '')
return `https://wa.me/${cleanNum}`
}
// WhatsApp Share deep link text
const getShareLink = () => {
const text = encodeURIComponent(`Marmaris Local'da harika bir yer keşfettim: ${name}\nDetayları incele: https://marmarislocal.com/${locale}/${categorySlug}/${listing.slug}`)
return `https://wa.me/?text=${text}`
}
return (
<div className="flex-1 flex flex-col min-h-screen bg-stone text-ink">
<Navbar />
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-10 flex-1">
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-10 flex-1 space-y-10">
{/* Breadcrumb / Category Link */}
<div className="mb-6 text-xs font-mono uppercase tracking-wider text-shutter flex items-center gap-2">
{/* Breadcrumb */}
<div className="text-xs font-mono uppercase tracking-wider text-shutter flex items-center gap-2">
<span className="hover:text-turquoise transition-colors">marmaris local</span>
<span>/</span>
<span className="hover:text-turquoise transition-colors">
@@ -72,8 +101,7 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
</div>
{/* Hero Details Block */}
<div className="bg-paper rounded-3xl border border-pine/8 p-6 sm:p-10 shadow-sm mb-10 space-y-8">
<div className="bg-paper rounded-3xl border border-pine/8 p-6 sm:p-10 shadow-sm space-y-8">
<div className="flex flex-col lg:flex-row gap-10">
{/* Left: Gallery Panel */}
@@ -107,8 +135,6 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
{/* Right: Info Panel */}
<div className="flex-1 flex flex-col justify-between space-y-6">
{/* Badge & Title */}
<div className="space-y-4">
<div className="flex flex-wrap gap-2.5 items-center">
<span className="text-[10px] font-mono text-bougainvillea font-bold uppercase tracking-wider bg-bougainvillea/5 border border-bougainvillea/10 px-2.5 py-1 rounded-full">
@@ -141,12 +167,12 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
</div>
{/* Description */}
<div className="text-ink/80 text-sm leading-relaxed font-medium">
<div className="text-ink/80 text-sm sm:text-base leading-relaxed font-medium">
{description}
</div>
{/* Contact Actions */}
<div className="space-y-4">
{/* Contact & Actions Grid */}
<div className="space-y-4 pt-2">
<h3 className="font-heading font-bold text-xs uppercase tracking-wider text-shutter">{t('contact')}</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
@@ -171,28 +197,52 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
{t('whatsapp')}
</a>
)}
{/* Menu Link */}
{listing.menuUrl && (
<a
href={listing.menuUrl}
target="_blank"
rel="noopener noreferrer"
className="flex items-center justify-center gap-2 bg-paper text-pine font-bold text-xs py-3.5 px-4 rounded-xl border border-pine/15 hover:bg-stone/50 transition sm:col-span-2"
>
<Globe className="w-4 h-4 text-turquoise" />
{t('viewMenu')}
</a>
)}
{/* Save Button (Favorites client action) */}
<SaveButton
listingId={listing.id}
saveLabel={t('save')}
savedLabel={t('saved')}
/>
</div>
{/* External links */}
<div className="flex gap-4 pt-2 text-xs font-semibold text-shutter">
<div className="flex flex-wrap gap-5 pt-2 text-xs font-semibold text-shutter">
{listing.website && (
<a href={listing.website} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1 hover:text-turquoise transition">
<Globe className="w-4 h-4" />
<a href={listing.website} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1.5 hover:text-turquoise transition">
<Globe className="w-4 h-4 text-turquoise" />
{t('website')}
</a>
)}
{listing.instagram && (
<a href={listing.instagram} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1 hover:text-turquoise transition">
<Globe className="w-4 h-4" />
<a href={`https://instagram.com/${listing.instagram}`} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1.5 hover:text-turquoise transition">
<Globe className="w-4 h-4 text-turquoise" />
{t('instagram')}
</a>
)}
{/* WhatsApp Share button */}
<a href={getShareLink()} target="_blank" rel="noopener noreferrer" className="flex items-center gap-1.5 hover:text-turquoise transition">
<Share2 className="w-4 h-4 text-turquoise" />
{t('shareWhatsapp')}
</a>
</div>
</div>
</div>
</div>
{/* Details footer (Hours & Location map) */}
@@ -245,15 +295,88 @@ export default async function ListingDetailPage({ params }: DetailPageProps) {
</div>
</div>
)}
</div>
</div>
{/* Instagram Feed Cache (Phase 2) */}
{instagramFeed && instagramPosts.length > 0 && (
<div className="bg-paper rounded-3xl border border-pine/8 p-6 sm:p-10 shadow-sm space-y-6">
<div className="flex items-center gap-3 border-b border-dashed border-pine/8 pb-4">
<div className="w-10 h-10 rounded-full border border-pine/10 flex items-center justify-center relative bg-stone shrink-0">
<span className="font-heading font-bold text-pine text-xs tracking-tighter">IG</span>
</div>
<div>
<h3 className="font-heading font-bold text-sm text-pine lowercase">@{instagramFeed.handle}</h3>
<p className="text-[10px] font-mono text-shutter uppercase tracking-wider mt-0.5">{t('instagramFeed')}</p>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
{instagramPosts.slice(0, 3).map((post: any, idx: number) => (
<a
key={idx}
href={post.permalink || '#'}
target="_blank"
rel="noopener noreferrer"
className="group relative aspect-square rounded-2xl overflow-hidden bg-stone border border-pine/5 shadow-sm block"
>
<img
src={post.imageUrl}
alt={post.caption || 'Instagram post'}
className="w-full h-full object-cover group-hover:scale-103 transition duration-500"
/>
<div className="absolute inset-0 bg-pine/70 opacity-0 group-hover:opacity-100 transition-opacity duration-300 p-4 flex flex-col justify-end">
<p className="text-[11px] text-stone font-medium line-clamp-3 leading-relaxed">
{post.caption}
</p>
</div>
</a>
))}
</div>
</div>
)}
{/* Newly Added Widget (Phase 2) */}
{latestListings.length > 0 && (
<div className="bg-paper rounded-3xl border border-pine/8 p-6 sm:p-10 shadow-sm space-y-6">
<div className="border-b border-dashed border-pine/8 pb-4">
<h3 className="text-lg font-heading font-extrabold text-pine lowercase">
{t('newlyAdded')}
</h3>
<p className="text-ink/65 text-xs font-medium mt-0.5">
{t('newlyAddedSubtitle')}
</p>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
{latestListings.map((newest) => {
const catSlug = newest.category?.slug || 'isletmeler'
const newestName = locale === 'en' ? newest.nameEn : locale === 'ru' ? newest.nameRu : newest.nameTr
const newestImg = newest.images && newest.images.length > 0 ? newest.images[0].url : 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?w=800&auto=format&fit=crop&q=80'
return (
<Link
key={newest.id}
href={`/${catSlug}/${newest.slug}`}
className="flex gap-4 items-center group bg-stone/20 p-3.5 rounded-2xl border border-pine/5 hover:border-turquoise/25 transition duration-150"
>
<div className="w-16 h-16 rounded-xl overflow-hidden bg-stone shrink-0 border border-pine/8">
<img src={newestImg} alt={newestName} className="w-full h-full object-cover group-hover:scale-105 transition duration-300" />
</div>
<div>
<h4 className="font-heading font-bold text-xs text-pine lowercase line-clamp-1 group-hover:text-turquoise transition-colors">{newestName}</h4>
<p className="text-[10px] text-shutter font-mono mt-0.5">{newest.neighborhood?.nameTr}</p>
</div>
</Link>
)
})}
</div>
</div>
)}
{/* Related Section */}
{relatedListings.length > 0 && (
<div className="space-y-6 pt-10">
<h3 className="text-xl font-heading font-extrabold text-pine lowercase">
<div className="space-y-6 pt-6">
<h3 className="text-xl font-heading font-extrabold text-pine lowercase border-b border-dashed border-pine/8 pb-3">
{t('related')}
</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8">
+399
View File
@@ -0,0 +1,399 @@
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
import { createOrUpdateBlogPostAction } from '@/app/actions'
import { ArrowLeft, Save, Eye, Edit3 } from 'lucide-react'
import { Link } from '@/i18n/routing'
interface Option {
value: string
label: string
}
interface FormProps {
post: any | null
listingOptions: Option[]
}
// Simple local markdown preview renderer helper
function previewMarkdown(md: string): string {
if (!md) return ''
let html = md
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
html = html.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
html = html.replace(/\*(.*?)\*/g, '<em>$1</em>')
html = html.replace(/^### (.*?)$/gm, '<h4 class="text-xs font-bold font-mono text-shutter uppercase tracking-wider mt-4 mb-1">$1</h4>')
html = html.replace(/^## (.*?)$/gm, '<h3 class="text-sm font-heading font-extrabold text-pine mt-5 mb-2 lowercase">$1</h3>')
html = html.replace(/^# (.*?)$/gm, '<h2 class="text-base font-heading font-extrabold text-pine mt-6 mb-3 lowercase">$1</h2>')
html = html.replace(/^\* (.*?)$/gm, '<li class="ml-4 list-disc text-xs text-ink/80">$1</li>')
html = html.replace(/^- (.*?)$/gm, '<li class="ml-4 list-disc text-xs text-ink/80">$1</li>')
html = html.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" class="text-turquoise hover:underline" target="_blank">$1</a>')
const paragraphs = html.split(/\n\n+/)
return paragraphs.map(p => {
const t = p.trim()
if (!t) return ''
if (t.startsWith('<h') || t.startsWith('<li') || t.startsWith('<ul')) return t
return `<p class="text-xs sm:text-sm text-ink/75 leading-relaxed mb-3">${t.replace(/\n/g, '<br/>')}</p>`
}).join('\n')
}
export default function BlogForm({ post, listingOptions }: FormProps) {
const router = useRouter()
const [activeTab, setActiveTab] = useState<'tr' | 'en' | 'ru'>('tr')
const [editorMode, setEditorMode] = useState<'edit' | 'preview'>('edit')
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
// Markdown content states for live preview
const [contentTr, setContentTr] = useState(post?.contentTr || '')
const [contentEn, setContentEn] = useState(post?.contentEn || '')
const [contentRu, setContentRu] = useState(post?.contentRu || '')
// Selected Listings
const [selectedListings, setSelectedListings] = useState<string[]>(post?.relatedListingIds || [])
const [listingSearch, setListingSearch] = useState('')
const handleListingToggle = (id: string) => {
setSelectedListings(prev =>
prev.includes(id) ? prev.filter(i => i !== id) : [...prev, id]
)
}
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
setLoading(true)
setError('')
setSuccess(false)
const formData = new FormData(e.currentTarget)
if (post) {
formData.append('id', post.id)
}
formData.append('relatedListingIds', selectedListings.join(','))
try {
const res = await createOrUpdateBlogPostAction(formData)
if (res.error) {
setError(res.error)
} else {
setSuccess(true)
setTimeout(() => {
router.push('/admin/blog')
router.refresh()
}, 1500)
}
} catch (err) {
setError('İşlem sırasında bir hata oluştu.')
} finally {
setLoading(false)
}
}
const filteredListings = listingOptions.filter(opt =>
opt.label.toLowerCase().includes(listingSearch.toLowerCase())
)
const activeContent = activeTab === 'tr' ? contentTr : activeTab === 'en' ? contentEn : contentRu
return (
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="bg-bougainvillea/10 border border-bougainvillea/25 text-bougainvillea p-4 rounded-xl text-xs font-semibold">
{error}
</div>
)}
{success && (
<div className="bg-turquoise/10 border border-turquoise/25 text-turquoise p-4 rounded-xl text-xs font-bold">
Yazı başarıyla kaydedildi! Yönlendiriliyorsunuz...
</div>
)}
{/* Language tabs */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between border-b border-pine/8 gap-4 pb-1">
<div className="flex gap-2">
{(['tr', 'en', 'ru'] as const).map((lang) => {
const label = lang === 'tr' ? '🇹🇷 Türkçe' : lang === 'en' ? '🇬🇧 English' : '🇷🇺 Русский'
const isTabActive = activeTab === lang
return (
<button
key={lang}
type="button"
onClick={() => setActiveTab(lang)}
className={`py-3 px-4 font-heading font-bold text-xs border-b-2 transition lowercase ${
isTabActive
? 'border-turquoise text-turquoise'
: 'border-transparent text-shutter hover:text-pine'
}`}
>
{label}
</button>
)
})}
</div>
{/* Edit / Preview controls */}
<div className="flex gap-1 bg-stone/50 p-1 rounded-xl border border-pine/5 shrink-0 self-start">
<button
type="button"
onClick={() => setEditorMode('edit')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-mono font-bold uppercase transition ${
editorMode === 'edit' ? 'bg-pine text-stone' : 'text-pine/70 hover:text-pine'
}`}
>
<Edit3 className="w-3.5 h-3.5" />
düzenle
</button>
<button
type="button"
onClick={() => setEditorMode('preview')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-[10px] font-mono font-bold uppercase transition ${
editorMode === 'preview' ? 'bg-pine text-stone' : 'text-pine/70 hover:text-pine'
}`}
>
<Eye className="w-3.5 h-3.5" />
önizleme
</button>
</div>
</div>
{/* Localized inputs */}
<div className="space-y-4">
{activeTab === 'tr' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Yazı Başlığı (TR) *</label>
<input
type="text"
name="titleTr"
required
defaultValue={post?.titleTr || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Marmaris'te Nerede Yenir? 2026 Rehberi"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">İçerik (TR - Markdown) *</label>
{editorMode === 'edit' ? (
<textarea
name="contentTr"
required
rows={10}
value={contentTr}
onChange={(e) => setContentTr(e.target.value)}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm font-medium focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono"
placeholder="Başlıklar için ##, listeler için - kullanın..."
/>
) : (
<div
className="w-full bg-stone/30 border border-dashed border-pine/10 rounded-xl px-6 py-4 min-h-[220px]"
dangerouslySetInnerHTML={{ __html: previewMarkdown(contentTr) }}
/>
)}
</div>
</div>
)}
{activeTab === 'en' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Yazı Başlığı (EN) *</label>
<input
type="text"
name="titleEn"
required
defaultValue={post?.titleEn || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Where to Eat in Marmaris? 2026 Guide"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">İçerik (EN - Markdown) *</label>
{editorMode === 'edit' ? (
<textarea
name="contentEn"
required
rows={10}
value={contentEn}
onChange={(e) => setContentEn(e.target.value)}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm font-medium focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono"
placeholder="English text in markdown..."
/>
) : (
<div
className="w-full bg-stone/30 border border-dashed border-pine/10 rounded-xl px-6 py-4 min-h-[220px]"
dangerouslySetInnerHTML={{ __html: previewMarkdown(contentEn) }}
/>
)}
</div>
</div>
)}
{activeTab === 'ru' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Yazı Başlığı (RU) *</label>
<input
type="text"
name="titleRu"
required
defaultValue={post?.titleRu || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Где поесть в Мармарисе? Путеводитель 2026"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">İçerik (RU - Markdown) *</label>
{editorMode === 'edit' ? (
<textarea
name="contentRu"
required
rows={10}
value={contentRu}
onChange={(e) => setContentRu(e.target.value)}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm font-medium focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono"
placeholder="Russian text in markdown..."
/>
) : (
<div
className="w-full bg-stone/30 border border-dashed border-pine/10 rounded-xl px-6 py-4 min-h-[220px]"
dangerouslySetInnerHTML={{ __html: previewMarkdown(contentRu) }}
/>
)}
</div>
</div>
)}
</div>
<hr className="border-dashed border-pine/8" />
{/* Global settings */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{/* Slug */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">URL Slug *</label>
<input
type="text"
name="slug"
required
defaultValue={post?.slug || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono"
placeholder="marmariste-nerede-yenir-2026"
/>
</div>
{/* Tags */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Etiketler (Virgülle ayırın)</label>
<input
type="text"
name="tags"
defaultValue={post?.tags?.join(', ') || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono text-xs"
placeholder="Gezilecek Yerler, Restoranlar, Rehber"
/>
</div>
{/* Cover image upload */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Kapak Görseli</label>
<input
type="file"
name="coverImageFile"
accept="image/*"
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink file:mr-3 file:py-1 file:px-2.5 file:rounded-lg file:border-0 file:text-xs file:font-semibold file:bg-pine file:text-stone hover:file:opacity-90 cursor-pointer"
/>
{post?.coverImage && (
<div className="mt-2 text-xs flex items-center gap-2">
<span className="text-shutter/65">Mevcut Kapak:</span>
<a href={post.coverImage} target="_blank" rel="noopener noreferrer" className="text-turquoise hover:underline font-mono truncate max-w-xs">{post.coverImage}</a>
<input type="hidden" name="coverImageUrl" value={post.coverImage} />
</div>
)}
</div>
{/* Publish Status */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Yayın Durumu</label>
<select
name="isPublished"
defaultValue={post?.publishedAt ? 'true' : 'false'}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
>
<option value="false">Taslak (Yayınlama)</option>
<option value="true">Yayında (Aktif)</option>
</select>
</div>
</div>
{/* Related Listings checkbox selection box */}
<div className="space-y-2 border-t border-dashed border-pine/8 pt-4">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Yazıyla İlişkili Mekanlar (Internal Links)</label>
<input
type="text"
value={listingSearch}
onChange={(e) => setListingSearch(e.target.value)}
className="bg-stone border border-pine/10 rounded-xl px-3 py-1.5 text-xs outline-none focus:ring-1 focus:ring-turquoise w-full sm:w-64 placeholder:text-shutter/60"
placeholder="Mekan ara..."
/>
</div>
<div className="border border-pine/10 bg-stone/20 rounded-2xl max-h-52 overflow-y-auto p-4 grid grid-cols-1 sm:grid-cols-2 gap-2">
{filteredListings.length === 0 ? (
<span className="text-xs text-shutter/60 col-span-2 py-4 text-center font-mono">Aradığınız mekan bulunamadı.</span>
) : (
filteredListings.map((opt) => {
const isChecked = selectedListings.includes(opt.value)
return (
<label
key={opt.value}
className={`flex items-center gap-2.5 p-2 rounded-xl border text-xs cursor-pointer select-none transition ${
isChecked ? 'bg-turquoise/5 border-turquoise/35 text-pine' : 'border-transparent text-ink/75 hover:bg-stone/50'
}`}
>
<input
type="checkbox"
checked={isChecked}
onChange={() => handleListingToggle(opt.value)}
className="accent-turquoise rounded w-3.5 h-3.5 shrink-0"
/>
<span className="truncate leading-none">{opt.label}</span>
</label>
)
})
)}
</div>
</div>
{/* Buttons */}
<div className="flex gap-4 pt-4 border-t border-dashed border-pine/8">
<Link
href="/admin/blog"
className="inline-flex items-center gap-1.5 px-5 py-3 border border-pine/20 rounded-xl text-xs font-bold text-pine hover:bg-stone/30 transition duration-150"
>
<ArrowLeft className="w-4 h-4" />
İptal
</Link>
<button
type="submit"
disabled={loading}
className="inline-flex items-center gap-1.5 px-5 py-3 bg-turquoise hover:bg-turquoise/90 disabled:opacity-75 text-paper rounded-xl text-xs font-bold shadow-sm transition duration-150"
>
<Save className="w-4 h-4" />
{loading ? 'Kaydediliyor...' : 'Yazıyı Kaydet'}
</button>
</div>
</form>
)
}
+48
View File
@@ -0,0 +1,48 @@
import { mockDb } from '@/lib/mockDb'
import BlogForm from './BlogForm'
import { notFound } from 'next/navigation'
interface Props {
params: Promise<{ locale: string; id: string }>
}
export default async function AdminBlogEditPage({ params }: Props) {
const { id } = await params
let post = null
if (id !== 'new') {
post = await mockDb.getBlogPostById(id)
if (!post) {
notFound()
}
}
// Fetch listings to link them to the blog post
const listings = await mockDb.getListings()
const listingOptions = listings.map(l => ({
value: l.id,
label: `${l.nameTr} (${l.neighborhood?.nameTr})`
}))
return (
<div className="space-y-6 max-w-5xl">
<div>
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">
{id === 'new' ? 'yeni blog yazısı' : 'yazıyı düzenle'}
</h2>
<p className="text-ink/65 text-xs font-medium mt-1">
{id === 'new'
? 'Yeni bir rehber veya gastronomi tanıtım yazısı oluşturun.'
: 'Mevcut blog yazısı içeriğini güncelleyin.'}
</p>
</div>
<div className="bg-paper border border-pine/8 rounded-3xl shadow-sm p-6 sm:p-8">
<BlogForm
post={post}
listingOptions={listingOptions}
/>
</div>
</div>
)
}
+124
View File
@@ -0,0 +1,124 @@
import { mockDb } from '@/lib/mockDb'
import { deleteBlogPostAction } from '@/app/actions'
import { Link } from '@/i18n/routing'
import { Edit, Trash, Plus, FileText, CheckCircle, XCircle } from 'lucide-react'
export default async function AdminBlogPage() {
const posts = await mockDb.getBlogPosts()
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">blog yazıları</h2>
<p className="text-ink/65 text-xs font-medium mt-1">
Marmaris Local rehberi için hazırlanan gezi, gastronomi ve tanıtım yazıları.
</p>
</div>
<Link
href="/admin/blog/new"
className="inline-flex items-center gap-1.5 bg-turquoise hover:bg-turquoise/90 text-paper text-xs font-bold py-3 px-5 rounded-xl shadow-sm transition active:scale-95 duration-150"
>
<Plus className="w-4 h-4" />
Yeni Yazı Ekle
</Link>
</div>
<div className="bg-paper border border-pine/8 rounded-2xl shadow-sm overflow-hidden">
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-pine/8 text-sm">
<thead className="bg-stone-deep/40 text-shutter font-mono text-[10px] uppercase tracking-wider">
<tr>
<th className="px-6 py-4 text-left">Görsel</th>
<th className="px-6 py-4 text-left">Yazı Başlığı (TR)</th>
<th className="px-6 py-4 text-left">URL Slug</th>
<th className="px-6 py-4 text-left">Etiketler</th>
<th className="px-6 py-4 text-left">Yayın Durumu</th>
<th className="px-6 py-4 text-right">İşlemler</th>
</tr>
</thead>
<tbody className="divide-y divide-dashed divide-pine/8 text-ink/80">
{posts.length === 0 ? (
<tr>
<td colSpan={6} className="px-6 py-12 text-center text-xs text-shutter font-medium">
Henüz blog yazısı eklenmemiş.
</td>
</tr>
) : (
posts.map((post) => {
return (
<tr key={post.id} className="hover:bg-stone/20 transition duration-150">
<td className="px-6 py-4 whitespace-nowrap">
<div className="h-12 w-16 relative rounded-lg overflow-hidden bg-stone border border-pine/8">
{post.coverImage ? (
<img src={post.coverImage} alt={post.titleTr} className="object-cover w-full h-full" />
) : (
<div className="w-full h-full flex items-center justify-center text-shutter bg-stone/50">
<FileText className="w-5 h-5" />
</div>
)}
</div>
</td>
<td className="px-6 py-4 font-medium">
<div className="font-heading font-bold text-pine lowercase text-sm">{post.titleTr}</div>
</td>
<td className="px-6 py-4 font-mono text-xs text-turquoise">
/blog/{post.slug}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<div className="flex flex-wrap gap-1">
{post.tags.map(tag => (
<span key={tag} className="bg-paper text-shutter border border-pine/10 px-2 py-0.5 rounded text-[10px] font-mono">
{tag}
</span>
))}
</div>
</td>
<td className="px-6 py-4 whitespace-nowrap">
{post.publishedAt ? (
<span className="inline-flex items-center gap-1 rounded-full bg-paper px-2.5 py-0.5 text-[10px] font-mono font-bold text-turquoise border border-turquoise/20 uppercase tracking-wider">
<CheckCircle className="w-3.5 h-3.5" />
Yayında
</span>
) : (
<span className="inline-flex items-center gap-1 rounded-full bg-paper px-2.5 py-0.5 text-[10px] font-mono font-medium text-shutter/65 border border-pine/8 uppercase tracking-wider">
<XCircle className="w-3.5 h-3.5" />
Taslak
</span>
)}
</td>
<td className="px-6 py-4 text-right whitespace-nowrap">
<div className="flex justify-end gap-2">
<Link
href={`/admin/blog/${post.id}`}
className="p-1.5 bg-paper text-shutter hover:text-turquoise hover:bg-turquoise/5 rounded-lg border border-pine/10 hover:border-turquoise/25 transition shadow-sm"
title="Düzenle"
>
<Edit className="w-4 h-4" />
</Link>
<form action={async () => {
'use server'
await deleteBlogPostAction(post.id)
}}>
<button
type="submit"
className="p-1.5 bg-paper text-shutter hover:text-bougainvillea hover:bg-bougainvillea/5 rounded-lg border border-pine/10 hover:border-bougainvillea/25 transition shadow-sm"
title="Sil"
>
<Trash className="w-4 h-4" />
</button>
</form>
</div>
</td>
</tr>
)
})
)}
</tbody>
</table>
</div>
</div>
</div>
)
}
@@ -0,0 +1,292 @@
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
import { createOrUpdateCollectionAction } from '@/app/actions'
import { ArrowLeft, Save } from 'lucide-react'
import { Link } from '@/i18n/routing'
interface Option {
value: string
label: string
}
interface FormProps {
collection: any | null
listingOptions: Option[]
}
export default function CollectionForm({ collection, listingOptions }: FormProps) {
const router = useRouter()
const [activeTab, setActiveTab] = useState<'tr' | 'en' | 'ru'>('tr')
const [loading, setLoading] = useState(false)
const [error, setError] = useState('')
const [success, setSuccess] = useState(false)
// Selected Listings
const [selectedListings, setSelectedListings] = useState<string[]>(collection?.listingIds || [])
const [listingSearch, setListingSearch] = useState('')
const handleListingToggle = (id: string) => {
setSelectedListings(prev =>
prev.includes(id) ? prev.filter(i => i !== id) : [...prev, id]
)
}
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
setLoading(true)
setError('')
setSuccess(false)
const formData = new FormData(e.currentTarget)
if (collection) {
formData.append('id', collection.id)
}
formData.append('listingIds', selectedListings.join(','))
try {
const res = await createOrUpdateCollectionAction(formData)
if (res.error) {
setError(res.error)
} else {
setSuccess(true)
setTimeout(() => {
router.push('/admin/collections')
router.refresh()
}, 1500)
}
} catch (err) {
setError('İşlem sırasında bir hata oluştu.')
} finally {
setLoading(false)
}
}
const filteredListings = listingOptions.filter(opt =>
opt.label.toLowerCase().includes(listingSearch.toLowerCase())
)
return (
<form onSubmit={handleSubmit} className="space-y-6">
{error && (
<div className="bg-bougainvillea/10 border border-bougainvillea/25 text-bougainvillea p-4 rounded-xl text-xs font-semibold">
{error}
</div>
)}
{success && (
<div className="bg-turquoise/10 border border-turquoise/25 text-turquoise p-4 rounded-xl text-xs font-bold">
Seçki başarıyla kaydedildi! Yönlendiriliyorsunuz...
</div>
)}
{/* Language tabs */}
<div className="border-b border-pine/8">
<div className="flex gap-2">
{(['tr', 'en', 'ru'] as const).map((lang) => {
const label = lang === 'tr' ? '🇹🇷 Türkçe' : lang === 'en' ? '🇬🇧 English' : '🇷🇺 Русский'
const isTabActive = activeTab === lang
return (
<button
key={lang}
type="button"
onClick={() => setActiveTab(lang)}
className={`py-3 px-4 font-heading font-bold text-xs border-b-2 transition lowercase ${
isTabActive
? 'border-turquoise text-turquoise'
: 'border-transparent text-shutter hover:text-pine'
}`}
>
{label}
</button>
)
})}
</div>
</div>
{/* Localized inputs */}
<div className="space-y-4">
{activeTab === 'tr' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Seçki Başlığı (TR) *</label>
<input
type="text"
name="titleTr"
required
defaultValue={collection?.titleTr || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Aile Dostu Restoranlar"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Açıklama (TR) *</label>
<textarea
name="descriptionTr"
required
rows={3}
defaultValue={collection?.descriptionTr || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Bu seçkinin odağını ve amacını açıklayın..."
/>
</div>
</div>
)}
{activeTab === 'en' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Seçki Başlığı (EN) *</label>
<input
type="text"
name="titleEn"
required
defaultValue={collection?.titleEn || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Family Friendly Restaurants"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Açıklama (EN) *</label>
<textarea
name="descriptionEn"
required
rows={3}
defaultValue={collection?.descriptionEn || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Describe this collection's focus..."
/>
</div>
</div>
)}
{activeTab === 'ru' && (
<div className="space-y-4">
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Seçki Başlığı (RU) *</label>
<input
type="text"
name="titleRu"
required
defaultValue={collection?.titleRu || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Örn: Семейные рестораны"
/>
</div>
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Açıklama (RU) *</label>
<textarea
name="descriptionRu"
required
rows={3}
defaultValue={collection?.descriptionRu || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink"
placeholder="Описание подборки..."
/>
</div>
</div>
)}
</div>
<hr className="border-dashed border-pine/8" />
{/* Global fields */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{/* Slug */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">URL Slug *</label>
<input
type="text"
name="slug"
required
defaultValue={collection?.slug || ''}
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink font-mono"
placeholder="aile-dostu-restoranlar"
/>
</div>
{/* Cover Image Upload */}
<div className="space-y-1.5">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Kapak Görseli</label>
<input
type="file"
name="coverImageFile"
accept="image/*"
className="w-full bg-stone border border-pine/10 rounded-xl px-4 py-3 text-sm focus:ring-1 focus:ring-turquoise outline-none text-ink file:mr-3 file:py-1 file:px-2.5 file:rounded-lg file:border-0 file:text-xs file:font-semibold file:bg-pine file:text-stone hover:file:opacity-90 cursor-pointer"
/>
{collection?.coverImage && (
<div className="mt-2 text-xs flex items-center gap-2">
<span className="text-shutter/65">Mevcut Görsel:</span>
<a href={collection.coverImage} target="_blank" rel="noopener noreferrer" className="text-turquoise hover:underline font-mono truncate max-w-xs">{collection.coverImage}</a>
<input type="hidden" name="coverImageUrl" value={collection.coverImage} />
</div>
)}
</div>
</div>
{/* Listing multi-select panel */}
<div className="space-y-2 border-t border-dashed border-pine/8 pt-4">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<label className="block text-xs font-mono uppercase tracking-wider text-shutter">Seçkide Yer Alan Mekanlar * ({selectedListings.length} seçildi)</label>
<input
type="text"
value={listingSearch}
onChange={(e) => setListingSearch(e.target.value)}
className="bg-stone border border-pine/10 rounded-xl px-3 py-1.5 text-xs outline-none focus:ring-1 focus:ring-turquoise w-full sm:w-64 placeholder:text-shutter/60"
placeholder="Mekan ara..."
/>
</div>
<div className="border border-pine/10 bg-stone/20 rounded-2xl max-h-52 overflow-y-auto p-4 grid grid-cols-1 sm:grid-cols-2 gap-2">
{filteredListings.length === 0 ? (
<span className="text-xs text-shutter/60 col-span-2 py-4 text-center font-mono">Aradığınız mekan bulunamadı.</span>
) : (
filteredListings.map((opt) => {
const isChecked = selectedListings.includes(opt.value)
return (
<label
key={opt.value}
className={`flex items-center gap-2.5 p-2 rounded-xl border text-xs cursor-pointer select-none transition ${
isChecked ? 'bg-turquoise/5 border-turquoise/35 text-pine font-bold' : 'border-transparent text-ink/75 hover:bg-stone/50'
}`}
>
<input
type="checkbox"
checked={isChecked}
onChange={() => handleListingToggle(opt.value)}
className="accent-turquoise rounded w-3.5 h-3.5 shrink-0"
/>
<span className="truncate leading-none">{opt.label}</span>
</label>
)
})
)}
</div>
</div>
{/* Buttons */}
<div className="flex gap-4 pt-4 border-t border-dashed border-pine/8">
<Link
href="/admin/collections"
className="inline-flex items-center gap-1.5 px-5 py-3 border border-pine/20 rounded-xl text-xs font-bold text-pine hover:bg-stone/30 transition duration-150"
>
<ArrowLeft className="w-4 h-4" />
İptal
</Link>
<button
type="submit"
disabled={loading}
className="inline-flex items-center gap-1.5 px-5 py-3 bg-turquoise hover:bg-turquoise/90 disabled:opacity-75 text-paper rounded-xl text-xs font-bold shadow-sm transition duration-150"
>
<Save className="w-4 h-4" />
{loading ? 'Kaydediliyor...' : 'Seçkiyi Kaydet'}
</button>
</div>
</form>
)
}
@@ -0,0 +1,48 @@
import { mockDb } from '@/lib/mockDb'
import CollectionForm from './CollectionForm'
import { notFound } from 'next/navigation'
interface Props {
params: Promise<{ locale: string; id: string }>
}
export default async function AdminCollectionEditPage({ params }: Props) {
const { id } = await params
let collection = null
if (id !== 'new') {
collection = await mockDb.getCollectionById(id)
if (!collection) {
notFound()
}
}
// Fetch listings for option list
const listings = await mockDb.getListings()
const listingOptions = listings.map(l => ({
value: l.id,
label: `${l.nameTr} (${l.neighborhood?.nameTr})`
}))
return (
<div className="space-y-6 max-w-5xl">
<div>
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">
{id === 'new' ? 'yeni seçki (koleksiyon)' : 'seçkiyi düzenle'}
</h2>
<p className="text-ink/65 text-xs font-medium mt-1">
{id === 'new'
? 'Yeni bir tematik mekan derlemesi oluşturun.'
: 'Mevcut kürasyon seki bilgilerini güncelleyin.'}
</p>
</div>
<div className="bg-paper border border-pine/8 rounded-3xl shadow-sm p-6 sm:p-8">
<CollectionForm
collection={collection}
listingOptions={listingOptions}
/>
</div>
</div>
)
}
+106
View File
@@ -0,0 +1,106 @@
import { mockDb } from '@/lib/mockDb'
import { deleteCollectionAction } from '@/app/actions'
import { Link } from '@/i18n/routing'
import { Edit, Trash, Plus, Layers } from 'lucide-react'
export default async function AdminCollectionsPage() {
const collections = await mockDb.getCollections()
return (
<div className="space-y-6">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4">
<div>
<h2 className="text-3xl font-heading font-extrabold text-pine lowercase">kürasyon seçkileri</h2>
<p className="text-ink/65 text-xs font-medium mt-1">
Rehberdeki işletmelerin tematik olarak gruplandırıldığı koleksiyonlar.
</p>
</div>
<Link
href="/admin/collections/new"
className="inline-flex items-center gap-1.5 bg-turquoise hover:bg-turquoise/90 text-paper text-xs font-bold py-3 px-5 rounded-xl shadow-sm transition active:scale-95 duration-150"
>
<Plus className="w-4 h-4" />
Yeni Seçki Ekle
</Link>
</div>
<div className="bg-paper border border-pine/8 rounded-2xl shadow-sm overflow-hidden">
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-pine/8 text-sm">
<thead className="bg-stone-deep/40 text-shutter font-mono text-[10px] uppercase tracking-wider">
<tr>
<th className="px-6 py-4 text-left">Görsel</th>
<th className="px-6 py-4 text-left">Koleksiyon Başlığı (TR)</th>
<th className="px-6 py-4 text-left">URL Slug</th>
<th className="px-6 py-4 text-left">Mekan Sayısı</th>
<th className="px-6 py-4 text-right">İşlemler</th>
</tr>
</thead>
<tbody className="divide-y divide-dashed divide-pine/8 text-ink/80">
{collections.length === 0 ? (
<tr>
<td colSpan={5} className="px-6 py-12 text-center text-xs text-shutter font-medium">
Henüz seçki eklenmemiş.
</td>
</tr>
) : (
collections.map((col) => {
const listingCount = col.listings?.length || 0
return (
<tr key={col.id} className="hover:bg-stone/20 transition duration-150">
<td className="px-6 py-4 whitespace-nowrap">
<div className="h-12 w-16 relative rounded-lg overflow-hidden bg-stone border border-pine/8">
{col.coverImage ? (
<img src={col.coverImage} alt={col.titleTr} className="object-cover w-full h-full" />
) : (
<div className="w-full h-full flex items-center justify-center text-shutter bg-stone/50">
<Layers className="w-5 h-5" />
</div>
)}
</div>
</td>
<td className="px-6 py-4 font-medium">
<div className="font-heading font-bold text-pine lowercase text-sm">{col.titleTr}</div>
<div className="text-xs text-ink/65 mt-0.5 line-clamp-1 max-w-xs">{col.descriptionTr}</div>
</td>
<td className="px-6 py-4 font-mono text-xs text-turquoise">
/secki/{col.slug}
</td>
<td className="px-6 py-4 font-mono text-xs text-pine font-semibold">
{listingCount} Mekan
</td>
<td className="px-6 py-4 text-right whitespace-nowrap">
<div className="flex justify-end gap-2">
<Link
href={`/admin/collections/${col.id}`}
className="p-1.5 bg-paper text-shutter hover:text-turquoise hover:bg-turquoise/5 rounded-lg border border-pine/10 hover:border-turquoise/25 transition shadow-sm"
title="Düzenle"
>
<Edit className="w-4 h-4" />
</Link>
<form action={async () => {
'use server'
await deleteCollectionAction(col.id)
}}>
<button
type="submit"
className="p-1.5 bg-paper text-shutter hover:text-bougainvillea hover:bg-bougainvillea/5 rounded-lg border border-pine/10 hover:border-bougainvillea/25 transition shadow-sm"
title="Sil"
>
<Trash className="w-4 h-4" />
</button>
</form>
</div>
</td>
</tr>
)
})
)}
</tbody>
</table>
</div>
</div>
</div>
)
}
+2
View File
@@ -12,6 +12,8 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
const navigation = [
{ name: 'Dashboard', href: '/admin', icon: LayoutDashboard },
{ name: 'Mekanlar', href: '/admin/listings', icon: ClipboardList },
{ name: 'Yazılar (Blog)', href: '/admin/blog', icon: FileText },
{ name: 'Seçkiler (Kürasyon)', href: '/admin/collections', icon: ClipboardList },
{ name: 'Başvurular', href: '/admin/submissions', icon: FileText },
{ name: 'Mesajlar', href: '/admin/messages', icon: Inbox },
{ name: 'Kategoriler', href: '/admin/categories', icon: LayoutDashboard },
+192
View File
@@ -0,0 +1,192 @@
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
// Bold
html = html.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
html = html.replace(/__(.*?)__/g, '<strong>$1</strong>')
// Italic
html = html.replace(/\*(.*?)\*/g, '<em>$1</em>')
html = html.replace(/_(.*?)_/g, '<em>$1</em>')
// Headings
html = html.replace(/^### (.*?)$/gm, '<h4 class="text-base font-heading font-bold text-pine mt-6 mb-2 lowercase">$1</h4>')
html = html.replace(/^## (.*?)$/gm, '<h3 class="text-lg font-heading font-extrabold text-pine mt-8 mb-3 lowercase">$1</h3>')
html = html.replace(/^# (.*?)$/gm, '<h2 class="text-xl font-heading font-extrabold text-pine mt-10 mb-4 lowercase">$1</h2>')
// Bullet Lists
html = html.replace(/^\* (.*?)$/gm, '<li class="ml-4 list-disc text-sm text-ink/80 leading-relaxed">$1</li>')
html = html.replace(/^- (.*?)$/gm, '<li class="ml-4 list-disc text-sm text-ink/80 leading-relaxed">$1</li>')
// Links
html = html.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" class="text-turquoise hover:underline" target="_blank" rel="noopener">$1</a>')
// Paragraphs
const blocks = html.split(/\n\n+/)
html = blocks.map(block => {
const trimmed = block.trim()
if (!trimmed) return ''
if (trimmed.startsWith('<h') || trimmed.startsWith('<li') || trimmed.startsWith('<ul') || trimmed.startsWith('<ol')) {
return trimmed
}
return `<p class="leading-relaxed mb-4 text-sm sm:text-base text-ink/80 font-medium">${trimmed.replace(/\n/g, '<br/>')}</p>`
}).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 */}
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<div className="bg-stone min-h-screen py-10 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-3xl mx-auto space-y-8">
{/* Back Link */}
<Link
href="/blog"
className="inline-flex items-center gap-1.5 px-4 py-2 border border-pine/10 rounded-xl text-xs font-mono font-bold text-pine hover:bg-paper transition"
>
<ArrowLeft className="w-3.5 h-3.5" />
GERİ DÖN
</Link>
{/* Article Box */}
<article className="bg-paper border border-pine/8 rounded-3xl overflow-hidden shadow-sm">
{post.coverImage && (
<div className="h-[350px] relative overflow-hidden bg-stone border-b border-pine/5">
<img
src={post.coverImage}
alt={title}
className="w-full h-full object-cover"
/>
</div>
)}
<div className="p-6 sm:p-10 space-y-6">
{/* Meta */}
<div className="flex flex-wrap items-center gap-4 text-xs text-shutter font-mono border-b border-dashed border-pine/8 pb-4">
<span className="flex items-center gap-1.5">
<Calendar className="w-4 h-4" />
{post.publishedAt ? new Date(post.publishedAt).toLocaleDateString(locale === 'tr' ? 'tr-TR' : locale === 'ru' ? 'ru-RU' : 'en-US') : ''}
</span>
{post.tags.map((tag) => (
<span key={tag} className="flex items-center gap-1 bg-stone/50 px-2 py-0.5 rounded-md border border-pine/5">
<Tag className="w-3.5 h-3.5" />
{tag}
</span>
))}
</div>
{/* Title */}
<h1 className="text-2xl sm:text-3xl font-heading font-extrabold text-pine lowercase leading-tight">
{title}
</h1>
{/* Markdown Content */}
<div
className="markdown-content space-y-4"
dangerouslySetInnerHTML={{ __html: htmlContent }}
/>
</div>
</article>
{/* Related Listings Section (Internal Linking) */}
{relatedListings.length > 0 && (
<div className="space-y-6 pt-6">
<h3 className="text-xl font-heading font-extrabold text-pine lowercase border-b border-dashed border-pine/8 pb-3">
yazıda geçen mekanlar
</h3>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-6">
{relatedListings.map((listing) => (
<ListingCard key={listing.id} listing={listing} />
))}
</div>
</div>
)}
</div>
</div>
</>
)
}
+110
View File
@@ -0,0 +1,110 @@
import { mockDb } from '@/lib/mockDb'
import { Link } from '@/i18n/routing'
import { getTranslations } from 'next-intl/server'
import { Calendar, Tag } from 'lucide-react'
export async function generateMetadata() {
return {
title: 'Marmaris Local Blog — Yerel Lezzet ve Gezi Rehberi',
description: 'Marmaris\'i bir yerel gibi keşfetmeniz için rehberler, nerede ne yenir tavsiyeleri ve gizli yerler.'
}
}
export default async function BlogIndexPage({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params
const t = await getTranslations('nav')
const posts = await mockDb.getBlogPosts(true)
return (
<div className="bg-stone min-h-screen py-10 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-5xl mx-auto space-y-10">
{/* Title */}
<div className="text-center space-y-3">
<span className="text-[10px] font-mono tracking-widest text-shutter uppercase bg-paper px-3 py-1.5 rounded-full border border-pine/5">
küratörlü rehberler
</span>
<h1 className="text-4xl font-heading font-extrabold text-pine lowercase">
marmaris local <span className="text-turquoise">blog</span>
</h1>
<p className="max-w-xl mx-auto text-ink/70 text-xs sm:text-sm font-medium">
Turistlerin gözünden kaçan yerel detaylar, en iyi lezzet durakları ve gizli gezi noktaları.
</p>
</div>
{/* Blog Posts Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{posts.length === 0 ? (
<div className="col-span-2 bg-paper border border-pine/8 p-12 text-center text-shutter text-sm rounded-3xl">
Henüz yayınlanmış bir yazı bulunmuyor.
</div>
) : (
posts.map((post) => {
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 snippet = content.substring(0, 140) + '...'
return (
<article
key={post.id}
className="bg-paper border border-pine/8 rounded-3xl overflow-hidden shadow-sm flex flex-col justify-between hover:border-turquoise/35 transition-all duration-300 hover:shadow-md"
>
<div>
{/* Cover image */}
{post.coverImage && (
<div className="h-56 relative overflow-hidden bg-stone border-b border-pine/5">
<img
src={post.coverImage}
alt={title}
className="w-full h-full object-cover hover:scale-105 transition duration-500"
/>
</div>
)}
{/* Post content preview */}
<div className="p-6 sm:p-8 space-y-4">
{/* Meta info */}
<div className="flex items-center gap-4 text-[10px] text-shutter font-mono">
<span className="flex items-center gap-1.5">
<Calendar className="w-3.5 h-3.5" />
{post.publishedAt ? new Date(post.publishedAt).toLocaleDateString(locale === 'tr' ? 'tr-TR' : locale === 'ru' ? 'ru-RU' : 'en-US') : ''}
</span>
{post.tags.length > 0 && (
<span className="flex items-center gap-1.5">
<Tag className="w-3.5 h-3.5" />
{post.tags[0]}
</span>
)}
</div>
<h2 className="font-heading font-extrabold text-lg text-pine hover:text-turquoise transition duration-150 lowercase leading-snug">
<Link href={`/blog/${post.slug}`}>
{title}
</Link>
</h2>
<p className="text-ink/75 text-xs sm:text-sm leading-relaxed">
{snippet}
</p>
</div>
</div>
<div className="px-6 sm:px-8 pb-6 sm:pb-8 pt-2">
<Link
href={`/blog/${post.slug}`}
className="inline-flex items-center text-xs font-mono font-bold text-turquoise hover:underline uppercase tracking-wider"
>
okumaya devam et
</Link>
</div>
</article>
)
})
)}
</div>
</div>
</div>
)
}
+118
View File
@@ -0,0 +1,118 @@
'use client'
import { useEffect, useState } from 'react'
import { useSearchParams } from 'next/navigation'
import ListingCard from '@/components/ListingCard'
import { Heart, Share2, ClipboardCheck } from 'lucide-react'
interface Props {
allListings: any[]
locale: string
}
export default function SavedClient({ allListings, locale }: Props) {
const searchParams = useSearchParams()
const [savedIds, setSavedIds] = useState<string[]>([])
const [copied, setCopied] = useState(false)
const [isClient, setIsClient] = useState(false)
useEffect(() => {
setIsClient(true)
const paramIds = searchParams.get('ids')
if (paramIds) {
// Load shared favorites
const ids = paramIds.split(',').filter(Boolean)
setSavedIds(ids)
// Save shared list to local storage as well
localStorage.setItem('savedListingIds', JSON.stringify(ids))
} else {
// Load personal favorites from localStorage
try {
const stored = localStorage.getItem('savedListingIds')
if (stored) {
setSavedIds(JSON.parse(stored))
}
} catch (e) {
console.error('Error reading localStorage:', e)
}
}
}, [searchParams])
const handleShare = () => {
if (savedIds.length === 0) return
const shareUrl = `${window.location.origin}${window.location.pathname}?ids=${savedIds.join(',')}`
navigator.clipboard.writeText(shareUrl).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 2000)
})
}
// Filter listings matching saved IDs
const filteredListings = allListings.filter(l => savedIds.includes(l.id))
if (!isClient) {
return (
<div className="py-20 text-center font-mono text-xs text-shutter animate-pulse">
liste yükleniyor...
</div>
)
}
return (
<div className="space-y-8">
{/* Title / Action bar */}
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 border-b border-dashed border-pine/8 pb-6">
<div>
<span className="text-[10px] font-mono tracking-widest text-shutter uppercase bg-paper px-3 py-1.5 rounded-full border border-pine/5">
kişisel rehberiniz
</span>
<h1 className="text-3xl font-heading font-extrabold text-pine lowercase mt-2.5">
kaydedilen <span className="text-turquoise">mekanlar</span>
</h1>
</div>
{savedIds.length > 0 && (
<button
onClick={handleShare}
className="inline-flex items-center gap-2 bg-turquoise hover:bg-turquoise/90 text-paper text-xs font-bold py-3 px-5 rounded-xl shadow-sm transition active:scale-95 duration-150 shrink-0 self-start"
>
{copied ? (
<>
<ClipboardCheck className="w-4 h-4 text-paper" />
Paylaşım Linki Kopyalandı!
</>
) : (
<>
<Share2 className="w-4 h-4 text-paper" />
Listeyi Paylaş (URL Kopyala)
</>
)}
</button>
)}
</div>
{/* Grid List */}
{filteredListings.length === 0 ? (
<div className="bg-paper border border-pine/8 rounded-3xl p-12 text-center space-y-4 max-w-xl mx-auto">
<div className="w-12 h-12 rounded-full bg-stone/50 border border-pine/5 flex items-center justify-center mx-auto text-shutter">
<Heart className="w-5 h-5 fill-transparent" />
</div>
<div>
<h3 className="font-heading font-bold text-pine lowercase text-sm">listeniz henüz boş</h3>
<p className="text-ink/65 text-xs mt-1.5 max-w-sm mx-auto leading-relaxed">
Mekan kartlarındaki kalp simgesine tıklayarak beğendiğiniz yerleri buraya ekleyebilir ve daha sonra hızlıca erişebilirsiniz.
</p>
</div>
</div>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredListings.map((listing) => (
<ListingCard key={listing.id} listing={listing} />
))}
</div>
)}
</div>
)
}
+25
View File
@@ -0,0 +1,25 @@
import { Suspense } from 'react'
import { mockDb } from '@/lib/mockDb'
import SavedClient from './SavedClient'
export async function generateMetadata() {
return {
title: 'Kaydedilen Yerler — Marmaris Local',
description: 'Marmaris rehberinde kaydettiğiniz ve beğendiğiniz tüm yerel adresler.'
}
}
export default async function SavedPage({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params
const allListings = await mockDb.getListings()
return (
<div className="bg-stone min-h-screen py-10 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-5xl mx-auto">
<Suspense fallback={<div className="text-xs font-mono py-12 text-center text-shutter">yükleniyor...</div>}>
<SavedClient allListings={allListings} locale={locale} />
</Suspense>
</div>
</div>
)
}
+1
View File
@@ -27,6 +27,7 @@ const ibmPlexMono = IBM_Plex_Mono({
export const metadata: Metadata = {
title: "Marmaris Local — Yerel Rehber",
description: "Marmaris'in en iyi yerel mekanları, restoranları ve saklı apart otelleri.",
manifest: "/manifest.json",
};
export function generateStaticParams() {
+91
View File
@@ -0,0 +1,91 @@
import { mockDb } from '@/lib/mockDb'
import { Link } from '@/i18n/routing'
import { notFound } from 'next/navigation'
import { ArrowLeft, Layers } 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 col = await mockDb.getCollectionBySlug(slug)
if (!col) return {}
return {
title: `${col.titleTr} Seçkisi — Marmaris Local`,
description: col.descriptionTr
}
}
export default async function CollectionDetailPage({ params }: Props) {
const { locale, slug } = await params
const col = await mockDb.getCollectionBySlug(slug)
if (!col) {
notFound()
}
const title = locale === 'en' ? col.titleEn : locale === 'ru' ? col.titleRu : col.titleTr
const desc = locale === 'en' ? col.descriptionEn : locale === 'ru' ? col.descriptionRu : col.descriptionTr
const listings = col.listings || []
return (
<div className="bg-stone min-h-screen py-10 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-5xl mx-auto space-y-8">
{/* Back Link */}
<Link
href="/seckiler"
className="inline-flex items-center gap-1.5 px-4 py-2 border border-pine/10 rounded-xl text-xs font-mono font-bold text-pine hover:bg-paper transition"
>
<ArrowLeft className="w-3.5 h-3.5" />
GERİ DÖN
</Link>
{/* Collection details banner */}
<div className="bg-paper border border-pine/8 rounded-3xl overflow-hidden shadow-sm flex flex-col md:flex-row gap-6 md:gap-8 p-6 sm:p-8">
{col.coverImage && (
<div className="w-full md:w-80 h-56 relative rounded-2xl overflow-hidden bg-stone shrink-0 border border-pine/5">
<img src={col.coverImage} alt={title} className="w-full h-full object-cover" />
</div>
)}
<div className="flex flex-col justify-center space-y-3">
<span className="text-[9px] font-mono tracking-widest text-turquoise uppercase font-bold flex items-center gap-1.5">
<Layers className="w-3.5 h-3.5" />
Editör Seçkisi
</span>
<h1 className="text-2xl sm:text-3xl font-heading font-extrabold text-pine lowercase leading-tight">
{title}
</h1>
<p className="text-ink/75 text-xs sm:text-sm leading-relaxed max-w-2xl font-medium">
{desc}
</p>
</div>
</div>
{/* Listings Grid */}
<div className="space-y-6">
<h2 className="text-lg font-heading font-extrabold text-pine lowercase border-b border-dashed border-pine/8 pb-3">
seçkide yer alan yerler ({listings.length})
</h2>
{listings.length === 0 ? (
<div className="bg-paper border border-pine/8 p-12 text-center text-shutter text-sm rounded-3xl">
Bu seçkiye henüz mekan eklenmemiş.
</div>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
{listings.map((listing) => (
<ListingCard key={listing.id} listing={listing} />
))}
</div>
)}
</div>
</div>
</div>
)
}
+98
View File
@@ -0,0 +1,98 @@
import { mockDb } from '@/lib/mockDb'
import { Link } from '@/i18n/routing'
import { getTranslations } from 'next-intl/server'
import { Layers } from 'lucide-react'
export async function generateMetadata() {
return {
title: 'Marmaris Local Seçkileri — Editör Kürasyonları',
description: 'Marmaris\'teki en iyi restoranlar, apartlar ve hizmetlerin özel tematik derlemeleri.'
}
}
export default async function CollectionsIndexPage({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params
const t = await getTranslations('nav')
const collections = await mockDb.getCollections()
return (
<div className="bg-stone min-h-screen py-10 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-5xl mx-auto space-y-10">
{/* Title */}
<div className="text-center space-y-3">
<span className="text-[10px] font-mono tracking-widest text-shutter uppercase bg-paper px-3 py-1.5 rounded-full border border-pine/5">
özel tematik listeler
</span>
<h1 className="text-4xl font-heading font-extrabold text-pine lowercase">
yerel onaylı <span className="text-turquoise">seçkiler</span>
</h1>
<p className="max-w-xl mx-auto text-ink/70 text-xs sm:text-sm font-medium">
Editörlerimizin deneyimlerine göre özenle hazırladığı, güncel kategorize edilmiş mekan listeleri.
</p>
</div>
{/* Collections Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
{collections.length === 0 ? (
<div className="col-span-2 bg-paper border border-pine/8 p-12 text-center text-shutter text-sm rounded-3xl">
Henüz eklenmiş bir seçki bulunmuyor.
</div>
) : (
collections.map((col) => {
const title = locale === 'en' ? col.titleEn : locale === 'ru' ? col.titleRu : col.titleTr
const desc = locale === 'en' ? col.descriptionEn : locale === 'ru' ? col.descriptionRu : col.descriptionTr
const listingCount = col.listings?.length || 0
return (
<div
key={col.id}
className="bg-paper border border-pine/8 rounded-3xl overflow-hidden shadow-sm flex flex-col justify-between hover:border-turquoise/35 transition-all duration-300 hover:shadow-md group"
>
<div>
{/* Cover image */}
{col.coverImage && (
<div className="h-56 relative overflow-hidden bg-stone border-b border-pine/5">
<img
src={col.coverImage}
alt={title}
className="w-full h-full object-cover group-hover:scale-103 transition duration-500"
/>
{/* Count tag */}
<span className="absolute top-4 right-4 bg-pine text-stone font-mono text-[9px] font-bold px-2.5 py-1 rounded-full uppercase tracking-wider">
{listingCount} Mekan
</span>
</div>
)}
<div className="p-6 sm:p-8 space-y-3">
<h2 className="font-heading font-extrabold text-lg text-pine group-hover:text-turquoise transition duration-150 lowercase leading-snug">
<Link href={`/secki/${col.slug}`}>
{title}
</Link>
</h2>
<p className="text-ink/75 text-xs sm:text-sm leading-relaxed line-clamp-3">
{desc}
</p>
</div>
</div>
<div className="px-6 sm:px-8 pb-6 sm:pb-8 pt-2">
<Link
href={`/secki/${col.slug}`}
className="inline-flex items-center gap-1.5 text-xs font-mono font-bold text-turquoise hover:underline uppercase tracking-wider"
>
listeyi incele
</Link>
</div>
</div>
)
})
)}
</div>
</div>
</div>
)
}
+133
View File
@@ -93,6 +93,7 @@ export async function approveSubmissionAction(id: string) {
priceRange: 2,
rating: 5.0,
isLocalApproved: false,
isFeatured: false,
images: submission.imageUrl ? [submission.imageUrl] : []
})
@@ -149,6 +150,7 @@ export async function createOrUpdateListingAction(formData: FormData) {
const priceRange = parseInt(formData.get('priceRange') as string)
const rating = formData.get('rating') ? parseFloat(formData.get('rating') as string) : null
const isLocalApproved = formData.get('isLocalApproved') === 'true'
const isFeatured = formData.get('isFeatured') === 'true'
const latitude = formData.get('latitude') ? parseFloat(formData.get('latitude') as string) : null
const longitude = formData.get('longitude') ? parseFloat(formData.get('longitude') as string) : null
@@ -209,6 +211,7 @@ export async function createOrUpdateListingAction(formData: FormData) {
priceRange,
rating,
isLocalApproved,
isFeatured,
latitude,
longitude,
openingHours,
@@ -230,3 +233,133 @@ export async function createOrUpdateListingAction(formData: FormData) {
return { success: false, error: err.message || 'Mekan kaydedilemedi.' }
}
}
// Blog Actions
export async function deleteBlogPostAction(id: string) {
await mockDb.deleteBlogPost(id)
revalidatePath('/admin/blog')
revalidatePath('/blog')
return { success: true }
}
export async function createOrUpdateBlogPostAction(formData: FormData) {
const id = formData.get('id') as string | null
const slug = formData.get('slug') as string
const titleTr = formData.get('titleTr') as string
const titleEn = formData.get('titleEn') as string
const titleRu = formData.get('titleRu') as string
const contentTr = formData.get('contentTr') as string
const contentEn = formData.get('contentEn') as string
const contentRu = formData.get('contentRu') as string
const tagsStr = formData.get('tags') as string || ''
const tags = tagsStr.split(',').map(t => t.trim()).filter(Boolean)
const relatedListingIdsStr = formData.get('relatedListingIds') as string || ''
const relatedListingIds = relatedListingIdsStr.split(',').map(i => i.trim()).filter(Boolean)
const isPublished = formData.get('isPublished') === 'true'
const publishedAt = isPublished ? new Date() : null
// Handle Cover Image
const coverImageFile = formData.get('coverImageFile') as File | null
let coverImage = formData.get('coverImageUrl') as string | null || null
if (coverImageFile && coverImageFile.size > 0) {
try {
coverImage = await uploadToOpeninary(coverImageFile, `blog/${slug}`)
} catch (e: any) {
console.error('Blog cover upload error:', e)
return { success: false, error: `Kapak görseli yüklenemedi: ${e.message}` }
}
}
const data = {
slug,
titleTr,
titleEn,
titleRu,
contentTr,
contentEn,
contentRu,
coverImage,
tags,
relatedListingIds,
publishedAt
}
try {
if (id && id !== 'new') {
await mockDb.updateBlogPost(id, data)
} else {
await mockDb.createBlogPost(data)
}
revalidatePath('/admin/blog')
revalidatePath('/blog')
revalidatePath(`/blog/${slug}`)
return { success: true }
} catch (err: any) {
return { success: false, error: err.message || 'Yazı kaydedilemedi.' }
}
}
// Collections Actions
export async function deleteCollectionAction(id: string) {
await mockDb.deleteCollection(id)
revalidatePath('/admin/collections')
revalidatePath('/seckiler')
return { success: true }
}
export async function createOrUpdateCollectionAction(formData: FormData) {
const id = formData.get('id') as string | null
const slug = formData.get('slug') as string
const titleTr = formData.get('titleTr') as string
const titleEn = formData.get('titleEn') as string
const titleRu = formData.get('titleRu') as string
const descriptionTr = formData.get('descriptionTr') as string
const descriptionEn = formData.get('descriptionEn') as string
const descriptionRu = formData.get('descriptionRu') as string
const listingIdsStr = formData.get('listingIds') as string || ''
const listingIds = listingIdsStr.split(',').map(i => i.trim()).filter(Boolean)
// Handle Cover Image
const coverImageFile = formData.get('coverImageFile') as File | null
let coverImage = formData.get('coverImageUrl') as string | null || null
if (coverImageFile && coverImageFile.size > 0) {
try {
coverImage = await uploadToOpeninary(coverImageFile, `collections/${slug}`)
} catch (e: any) {
console.error('Collection cover upload error:', e)
return { success: false, error: `Kapak görseli yüklenemedi: ${e.message}` }
}
}
const data = {
slug,
titleTr,
titleEn,
titleRu,
descriptionTr,
descriptionEn,
descriptionRu,
coverImage,
listingIds
}
try {
if (id && id !== 'new') {
await mockDb.updateCollection(id, data)
} else {
await mockDb.createCollection(data)
}
revalidatePath('/admin/collections')
revalidatePath('/seckiler')
revalidatePath(`/secki/${slug}`)
return { success: true }
} catch (err: any) {
return { success: false, error: err.message || 'Koleksiyon kaydedilemedi.' }
}
}
+65
View File
@@ -0,0 +1,65 @@
import { NextRequest, NextResponse } from 'next/server'
import { mockDb } from '@/lib/mockDb'
export async function POST(req: NextRequest) {
const authHeader = req.headers.get('Authorization')
const secret = process.env.CRON_SECRET || 'secret-token-key-123'
if (authHeader !== `Bearer ${secret}`) {
return new NextResponse('Unauthorized', { status: 401 })
}
// Get listings that have instagram handle filled
const listings = await mockDb.getListings()
const activeListings = listings.filter(l => l.instagram)
const syncResults = []
for (const listing of activeListings) {
const handle = listing.instagram!
let posts = []
if (process.env.USE_MOCK === 'true') {
// In mock/demo mode, return simulated posts with high quality Unsplash placeholders
posts = [
{ imageUrl: 'https://images.unsplash.com/photo-1544025162-d76694265947?w=500&auto=format&fit=crop&q=80', caption: `Mezelerimiz taze taze hazırlandı! 🐟 @${handle}`, permalink: '#', postedAt: new Date().toISOString() },
{ imageUrl: 'https://images.unsplash.com/photo-1519708227418-c8fd9a32b7a2?w=500&auto=format&fit=crop&q=80', caption: `Bu akşam iskelede gün batımı bir başka güzel... 🌅 @${handle}`, permalink: '#', postedAt: new Date().toISOString() },
{ imageUrl: 'https://images.unsplash.com/photo-1476224203421-9ac39bcb3327?w=500&auto=format&fit=crop&q=80', caption: `Marmaris'in lezzet keyfini kaçırmayın! 🍽️ @${handle}`, permalink: '#', postedAt: new Date().toISOString() }
]
} else {
const apiKey = process.env.RAPIDAPI_KEY
const host = process.env.RAPIDAPI_INSTAGRAM_HOST || 'instagram-scraper-api2.p.rapidapi.com'
if (apiKey) {
try {
const res = await fetch(`https://${host}/v1/user/posts?username=${handle}`, {
headers: {
'x-rapidapi-key': apiKey,
'x-rapidapi-host': host
}
})
if (res.ok) {
const resultData = await res.json()
const items = resultData?.data?.items || []
posts = items.slice(0, 3).map((item: any) => ({
imageUrl: item.image_versions2?.candidates?.[0]?.url || item.thumbnail_url,
caption: item.caption?.text || '',
permalink: `https://instagram.com/p/${item.code}`,
postedAt: new Date(item.taken_at * 1000).toISOString()
}))
}
} catch (e) {
console.error(`Error scraping Instagram for @${handle}:`, e)
}
}
}
if (posts.length > 0) {
await mockDb.updateInstagramFeedCache(listing.id, handle, posts)
syncResults.push({ id: listing.id, handle, postsCount: posts.length })
}
}
return NextResponse.json({ success: true, synced: syncResults })
}
+58
View File
@@ -0,0 +1,58 @@
import { mockDb } from '@/lib/mockDb'
export async function GET() {
const baseUrl = 'https://marmarislocal.com'
// Fetch data
const posts = await mockDb.getBlogPosts(true)
const listings = await mockDb.getListings({ isLocalApproved: true })
// Construct XML
let xml = `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Marmaris Local</title>
<link>${baseUrl}</link>
<description>Marmaris'in yerel rehberi, gurme mekanları ve gezilecek gizli yerleri.</description>
<language>tr</language>
<lastBuildDate>${new Date().toUTCString()}</lastBuildDate>
<atom:link href="${baseUrl}/feed.xml" rel="self" type="application/rss+xml" />
`
// Add blog posts
for (const post of posts.slice(0, 10)) {
const pubDate = post.publishedAt ? new Date(post.publishedAt).toUTCString() : new Date(post.createdAt).toUTCString()
xml += ` <item>
<title><![CDATA[${post.titleTr}]]></title>
<link>${baseUrl}/tr/blog/${post.slug}</link>
<guid>${baseUrl}/tr/blog/${post.slug}</guid>
<pubDate>${pubDate}</pubDate>
<description><![CDATA[${post.contentTr.substring(0, 200)}...]]></description>
</item>
`
}
// Add newly added approved listings
for (const listing of listings.slice(0, 10)) {
const pubDate = new Date(listing.createdAt).toUTCString()
const catSlug = listing.category?.slug || 'isletmeler'
xml += ` <item>
<title><![CDATA[Yeni Onaylandı: ${listing.nameTr} (${listing.neighborhood?.nameTr})]]></title>
<link>${baseUrl}/tr/${catSlug}/${listing.slug}</link>
<guid>${baseUrl}/tr/${catSlug}/${listing.slug}</guid>
<pubDate>${pubDate}</pubDate>
<description><![CDATA[${listing.descriptionTr}]]></description>
</item>
`
}
xml += `</channel>
</rss>`
return new Response(xml, {
headers: {
'Content-Type': 'application/xml; charset=utf-8',
'Cache-Control': 'public, s-maxage=86400, stale-while-revalidate=43200'
}
})
}