This commit is contained in:
Andrea
2024-05-11 11:58:19 +02:00
parent 4a13e34f84
commit e30b2cc403
6 changed files with 2825 additions and 6043 deletions

View File

@@ -1,6 +1,7 @@
import { remarkCodeHike } from "@code-hike/mdx";
import { readdir, readFile } from "fs/promises";
import { bundleMDX } from "mdx-bundler";
import path from "path";
type FrontMatter = {
title: string;
@@ -9,8 +10,9 @@ type FrontMatter = {
};
export const getMdxFile = async (file: string) => {
const filePath = path.join(process.cwd(), `posts/${file}.mdx`);
return bundleMDX<FrontMatter>({
source: (await readFile(`posts/${file}.mdx`)).toString(),
source: (await readFile(filePath)).toString(),
mdxOptions(options) {
return {
rehypePlugins: [...(options.rehypePlugins ?? [])],
@@ -37,8 +39,9 @@ export const findPosts = async () => {
filename: string;
})[] = [];
for (const file of files.filter((file) => file.endsWith(".mdx"))) {
const filePath = path.join(process.cwd(), `posts/${file}`);
const { frontmatter } = await bundleMDX<FrontMatter>({
source: (await readFile(`posts/${file}`)).toString(),
source: (await readFile(filePath)).toString(),
mdxOptions() {
return {
remarkPlugins: [