Files
blog/routes/posts/[slug]/index.server.ts
2026-02-13 13:41:18 +01:00

22 lines
685 B
TypeScript

import { getParams, html, htmlToResponse, readDir } from "@mastrojs/mastro";
import { readMarkdownFile } from "@mastrojs/markdown";
import { Layout } from "../../../components/Layout.ts";
export const GET = async (req: Request) => {
const { slug } = getParams(req);
const post = await readMarkdownFile(`data/posts/${slug}.md`);
return htmlToResponse(
Layout({
title: post.meta.title,
children: html`<article class="prose prose-stone prose-invert">
${post.content}
</article>`,
}),
);
};
export const getStaticPaths = async () => {
const posts = await readDir("data/posts/");
return posts.map((p) => "/posts/" + p.slice(0, -3) + "/");
};