almost done
This commit is contained in:
18
lib/post.ts
Normal file
18
lib/post.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user