Files
website/lib/post.ts
2025-09-12 23:20:36 +02:00

19 lines
473 B
TypeScript

import fs from "fs";
import path from "path";
import matter from "gray-matter";
const postsDirectory = path.join(process.cwd(), "..", "_posts");
export async function getPostData(category: string, id: string) {
const fullPath = path.join(postsDirectory, category, `${id}.md`);
const fileContents = fs.readFileSync(fullPath, "utf8");
const matterResult = matter(fileContents);
return {
id,
content: matterResult.content,
...matterResult.data,
};
}