const fs = require("fs").promises; const pathRoot = "blog"; async function recursiveTree(dir) { const res = new Map(); const entries = await fs.readdir(dir, { withFileTypes: true }); for (const entry of entries) { if (entry.name[0] == ".") continue; if (entry.isDirectory()) { res.set(entry.name, await recursiveTree(dir + "/" + entry.name)); } else if (entry.isFile() && entry.name.endsWith(".html")) { res.set(entry.name.slice(0, entry.name.length - 5), true); } } return res; } function generateTree(tree, path) { let out = ""; for (const [entry, sub] of tree) { if (sub === true) { // file const elt = `
\n`; out += elt; } else { // subdirectory out += '