import fs from 'fs/promises' import path from 'path' async function handlePath(dirName, siteMap) { // Get all directories in the 'dirName' const dirs = await fs.readdir(dirName) // For each file in the directory: check if it is a // file or a folder, if a folder recursively run this // function in that folder. for (const dirIndex in dirs) { const file = dirs[dirIndex] const fullPath = path.join(dirName, file) const fileStats = await fs.stat(fullPath) if (fileStats.isDirectory()) siteMap[fullPath.replace(/^[\s\S]+\/pages/, "")] = { path: fullPath, address: fullPath.replace(/^[\s\S]+\/pages/, ""), type: "directory", children: await handlePath(fullPath, {}) } else siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] = { path: fullPath, address: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, ""), type: "file" } } return siteMap } function renderSiteMap(siteMap, entrypoint) { // Make a template for the sitemap and recursively run // for all directories with children. return `