mirror of
https://github.com/timmypidashev/web.git
synced 2026-04-14 11:03:50 +00:00
Begin rewrite to astro
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
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,
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user