'use client'; import { useEffect, useState } from 'react'; import { format } from 'date-fns'; import Link from 'next/link'; interface Post { slug: string; title: string; date: string; tags: string[]; summary: string; content: string; createdAt: string; } export default function PostPage({ params }: { params: { slug: string[] } }) { const [post, setPost] = useState(null); // Join the slug array to get the full path const slugPath = Array.isArray(params.slug) ? params.slug.join('/') : params.slug; useEffect(() => { // Initial load loadPost(); // Set up polling for changes const interval = setInterval(loadPost, 2000); // Cleanup return () => clearInterval(interval); }, [slugPath]); const loadPost = async () => { try { const response = await fetch(`/api/posts/${encodeURIComponent(slugPath)}`); const data = await response.json(); setPost(data); } catch (error) { console.error('Fehler beim Laden des Beitrags:', error); } }; if (!post) { return
Lädt...
; } return (
← Zurück zu den Beiträgen

{post.title}

Veröffentlicht: {format(new Date(post.date), 'd. MMMM yyyy')}
Erstellt: {format(new Date(post.createdAt), 'd. MMMM yyyy HH:mm')}
{post.tags.map((tag) => ( {tag} ))}
); }