MCPcopy Create free account
hub / github.com/LevelUpWeb3/app / processContentMarkdownFiles

Function processContentMarkdownFiles

scripts/processContentMarkdown.js:9–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7const publicDirectory = path.join(process.cwd(), "public/data/contents");
8
9const processContentMarkdownFiles = async () => {
10 const fileNames = fs.readdirSync(markdownDirectory);
11
12 const allContentDataPromises = fileNames.map(async (fileName) => {
13 const id = fileName.replace(/\.mdx$/, "");
14
15 const fullPath = path.join(markdownDirectory, fileName);
16 const fileContents = fs.readFileSync(fullPath, "utf8");
17
18 const { data } = matter(fileContents);
19
20 if (!data.name) return null;
21
22 const contentData = {
23 id,
24 ...data,
25 };
26 const individualOutputPath = path.join(publicDirectory, `${id}.mdx`);
27
28 if (!fs.existsSync(publicDirectory))
29 fs.mkdirSync(publicDirectory, { recursive: true });
30 fs.writeFileSync(individualOutputPath, fileContents);
31
32 return contentData;
33 });
34
35 const allContentData = await Promise.all(allContentDataPromises);
36
37 const markdownData = allContentData
38 .filter((data) => data)
39 .sort(({ index: a }, { index: b }) => {
40 return a - b;
41 });
42
43 fs.writeFileSync(
44 path.join(JSONDirectory, "markdownData.json"),
45 JSON.stringify(markdownData, null, 2),
46 ); // Pretty print JSON
47};
48
49processContentMarkdownFiles().catch(console.error);

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected