MD Files in App Dir
Answered
Arinji posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/cba9267c0173c6acfde7fa4ba0e70f94.webp?size=256)
ArinjiOP
ok so i have an array of objects in the DocMap file whichh maps a url to a markdown file
And i am trying to use the markdown file in the page.tsx.
But i get a fetch error, how do i do this lol
I cant put it in the public folder btw cause we dont want it so people can just get the md file
export const MINECRAFTDOCS = [
{
link: "minecraft-server-management-the-basics-ig1n62",
docFile: "../DocFiles/minecraft-custom-ip.md",
},
];
And i am trying to use the markdown file in the page.tsx.
import { MINECRAFTDOCS } from "@/DOCMAPS/minecraft";
import { notFound } from "next/navigation";
async function GetMDFilename(link: string) {
const filename = MINECRAFTDOCS.find((doc) => doc.link === link);
if (!filename) notFound();
const file = await fetch(`${filename.docFile}`);
return { filename, file };
}
export default async function Page({ params }: { params: { link: string } }) {
const { filename, file } = await GetMDFilename(params.link);
console.log(filename, file);
return (
<main className=" min-h-[100svh] w-full flex flex-col items-center justify-center bg-shades-darkgrey"></main>
);
}
But i get a fetch error, how do i do this lol
I cant put it in the public folder btw cause we dont want it so people can just get the md file
![Image](https://cdn.discordapp.com/attachments/1202828483852640306/1202828483982655528/image.png?ex=65cee052&is=65bc6b52&hm=0fed38fe6a803f0f6a7aa47b5b7466617f2e7d31e8b8f04aa57ee0e6b4e425b1&)
Answered by Ray
try this
import fs from "fs/promises";
import path from "path";
const file = await fs.readFile(path.join(process.cwd(), 'src/Docfiles/minecraft-custom-ip.md'));
2 Replies
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
try this
import fs from "fs/promises";
import path from "path";
const file = await fs.readFile(path.join(process.cwd(), 'src/Docfiles/minecraft-custom-ip.md'));
Answer
![Avatar](https://cdn.discordapp.com/avatars/890486507872342027/cba9267c0173c6acfde7fa4ba0e70f94.webp?size=256)
ArinjiOP
works, thanks :D