From 9c2e65206d65682b163e3b722bcb99c559321de2 Mon Sep 17 00:00:00 2001 From: Florian <45694132+flo-bit@users.noreply.github.com> Date: Mon, 27 Oct 2025 19:25:45 +0100 Subject: [PATCH] update rename --- scripts/update-config.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/scripts/update-config.js b/scripts/update-config.js index 1c6275b..c67605e 100644 --- a/scripts/update-config.js +++ b/scripts/update-config.js @@ -1,4 +1,5 @@ import fs from "node:fs"; +import path from "node:path"; const CONFIG_PATH = "tdocs.config.json"; @@ -52,11 +53,25 @@ console.log( console.log("\nšŸ” Result:\n" + fs.readFileSync(CONFIG_PATH, "utf8")); -// rename all .md files to .mdx in root folder and subfolders recursively -const mdFiles = fs.readdirSync(".", { withFileTypes: true, recursive: true }) - .filter(dirent => dirent.isFile() && dirent.name.endsWith(".md")) - .map(dirent => dirent.name); +function renameMdToMdx(dir = process.cwd()) { + // Read all items in the current directory + const items = fs.readdirSync(dir, { withFileTypes: true }); -for (const mdFile of mdFiles) { - fs.renameSync(mdFile, mdFile.replace(".md", ".mdx")); -} \ No newline at end of file + for (const item of items) { + const fullPath = path.join(dir, item.name); + + if (item.isDirectory()) { + // Recurse into subdirectories + renameMdToMdx(fullPath); + } else if (item.isFile() && path.extname(item.name) === ".md") { + const newName = path.basename(item.name, ".md") + ".mdx"; + const newPath = path.join(dir, newName); + + fs.renameSync(fullPath, newPath); + console.log(`Renamed: ${fullPath} → ${newPath}`); + } + } +} + +// Run the function +renameMdToMdx(); \ No newline at end of file -- 2.51.2