()
| 24 | }; |
| 25 | |
| 26 | const processEventsMarkdownFiles = async () => { |
| 27 | const filePaths = collectMdxFiles(markdownDirectory); |
| 28 | |
| 29 | const allEventsDataPromises = filePaths.map( |
| 30 | async ({ fullPath, relativePath }) => { |
| 31 | const id = relativePath.replace(/\.mdx$/, "").replace(/\//g, "_"); |
| 32 | |
| 33 | const fileContents = fs.readFileSync(fullPath, "utf8"); |
| 34 | |
| 35 | const { data } = matter(fileContents); |
| 36 | if (!data.title) return null; |
| 37 | |
| 38 | const eventsData = { |
| 39 | id, |
| 40 | ...data, |
| 41 | }; |
| 42 | |
| 43 | const outputDir = path.join(outputDirectory, path.dirname(relativePath)); |
| 44 | const individualOutputPath = path.join(outputDir, `${id}.mdx`); |
| 45 | |
| 46 | if (!fs.existsSync(outputDir)) |
| 47 | fs.mkdirSync(outputDir, { recursive: true }); |
| 48 | fs.writeFileSync(individualOutputPath, fileContents); |
| 49 | |
| 50 | return eventsData; |
| 51 | }, |
| 52 | ); |
| 53 | |
| 54 | const allEventsData = await Promise.all(allEventsDataPromises); |
| 55 | |
| 56 | const markdownData = allEventsData |
| 57 | .filter((data) => data) |
| 58 | .sort(({ index: a }, { index: b }) => { |
| 59 | return a - b; |
| 60 | }); |
| 61 | |
| 62 | fs.writeFileSync( |
| 63 | path.join(JSONDirectory, "markdownData.json"), |
| 64 | JSON.stringify(markdownData, null, 2), |
| 65 | ); // Pretty print JSON |
| 66 | }; |
| 67 | |
| 68 | processEventsMarkdownFiles().catch(console.error); |
no test coverage detected