---
import { fetchSkayle, type JsonApiResource } from "../../lib/skayle-cms";
type CmsPost = {
title: string;
slug: string;
excerpt: string | null;
content_html: string | null;
};
type ListResponse = { data: Array<JsonApiResource<CmsPost>> };
type SingleResponse = { data: JsonApiResource<CmsPost> | null };
export async function getStaticPaths() {
const list = await fetchSkayle<ListResponse>(
"/articles?status=published&orderby=date&order=desc&page=1&per_page=100",
);
return list.data.map((post) => ({
params: { slug: post.attributes.slug },
}));
}
const { slug } = Astro.params;
const postResponse = await fetchSkayle<SingleResponse>(`/articles/${encodeURIComponent(slug || "")}`);
const post = postResponse.data;
if (!post) {
throw new Error("Post not found");
}
---
<html>
<body>
<article>
<h1>{post.attributes.title}</h1>
{post.attributes.excerpt ? <p>{post.attributes.excerpt}</p> : null}
<div set:html={post.attributes.content_html || ""} />
</article>
</body>
</html>