mirror of
https://github.com/timmypidashev/web.git
synced 2026-04-14 02:53:51 +00:00
31 lines
831 B
JavaScript
31 lines
831 B
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
import { compileMDX } from "next-mdx-remote/rsc";
|
|
import rehypeHighlight from "rehype-highlight";
|
|
import remarkGfm from "remark-gfm";
|
|
|
|
const contentDir = path.join(process.cwd(), "app/blog/posts");
|
|
|
|
export async function getBlogBySlug(slug) {
|
|
const filePath = path.join(contentDir, `${slug}.mdx`);
|
|
const source = fs.readFileSync(filePath, "utf8");
|
|
const { frontmatter, content } = await compileMDX({
|
|
source,
|
|
options: {
|
|
parseFrontmatter: true,
|
|
mdxOptions: {
|
|
remarkPlugins: [remarkGfm],
|
|
rehypePlugins: [rehypeHighlight],
|
|
},
|
|
},
|
|
});
|
|
return { frontmatter, content, slug };
|
|
}
|
|
|
|
export async function getAllBlogSlugs() {
|
|
const files = fs.readdirSync(contentDir);
|
|
return files.map(file => ({
|
|
slug: path.parse(file).name,
|
|
}));
|
|
}
|