--- import Layout from '../../layouts/Layout.astro'; import { marked } from 'marked'; const { slug } = Astro.params; const API_URL = (typeof process !== 'undefined' ? process.env.PUBLIC_API_URL : import.meta.env.PUBLIC_API_URL) || 'http://localhost:3000'; interface PostDetail { slug: string; content: string; } let post: PostDetail | null = null; let html = ''; let error = ''; try { const response = await fetch(`${API_URL}/api/posts/${slug}`); if (response.ok) { post = await response.json(); if (post) { html = await marked.parse(post.content); } } else { error = 'Post not found'; } } catch (e) { error = 'Could not connect to backend'; } function formatSlug(slug: string) { return slug .split('-') .map(word => word.charAt(0).toUpperCase() + word.slice(1)) .join(' '); } ---
Back to list {post && (

{formatSlug(post.slug)}

)}
{error && (

{error}

Return home
)} {post && (
)}