diff --git a/app/utils/posts.server.ts b/app/utils/posts.server.ts index 87f1d5b..3d65c8f 100644 --- a/app/utils/posts.server.ts +++ b/app/utils/posts.server.ts @@ -1,7 +1,6 @@ import { remarkCodeHike } from "@code-hike/mdx"; import { readdir, readFile } from "fs/promises"; import { bundleMDX } from "mdx-bundler"; -import path from "path"; import codeHikeTheme from "shiki/themes/one-dark-pro.json"; type FrontMatter = { @@ -12,9 +11,7 @@ type FrontMatter = { export const getMdxFile = async (file: string) => { return bundleMDX({ - source: ( - await readFile(path.join(process.cwd(), `./posts/${file}.mdx`)) - ).toString(), + source: (await readFile(`${__dirname}/../posts/${file}.mdx`)).toString(), mdxOptions(options) { return { rehypePlugins: [...(options.rehypePlugins ?? [])], @@ -36,15 +33,13 @@ export const getMdxFile = async (file: string) => { }; export const findPosts = async () => { - const files = await readdir(path.join(process.cwd(), "./posts")); + const files = await readdir(`${__dirname}/../posts`); const posts: (FrontMatter & { filename: string; })[] = []; for (const file of files.filter((file) => file.endsWith(".mdx"))) { const { frontmatter } = await bundleMDX({ - source: ( - await readFile(path.join(process.cwd(), `./posts/${file}`)) - ).toString(), + source: (await readFile(`${__dirname}/../posts/${file}`)).toString(), mdxOptions() { return { remarkPlugins: [