---
/**
 * Single Page
 */

import { getEmDashEntry } from "emdash";
import { PortableText } from "emdash/ui";
import Base from "../../layouts/Base.astro";

const { slug } = Astro.params;

const { entry: page, error } = await getEmDashEntry("pages", slug!);

if (error) {
	return new Response("Server error", { status: 500 });
}

if (!page) {
	return Astro.redirect("/404");
}
---

<Base title={page.data.title}>
	<article class="container">
		<div class="content-width">
			<header class="page-header">
				<h1>{page.data.title}</h1>
			</header>

			<div class="prose">
				{page.data.content && <PortableText value={page.data.content} />}
			</div>
		</div>
	</article>
</Base>
