Skip to content

Instantly share code, notes, and snippets.

@hatemhosny
Created February 24, 2025 09:38
Show Gist options
  • Save hatemhosny/f5b691dbe102b12f8b6d6e5b731402b6 to your computer and use it in GitHub Desktop.
Save hatemhosny/f5b691dbe102b12f8b6d6e5b731402b6 to your computer and use it in GitHub Desktop.
change extension from md to mdx using git
const { resolve } = require('path');
const { readdir } = require('fs').promises;
const { exec } = require('child_process');
const DIRECTORY = 'docs';
async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
if (dirent.isDirectory()) {
yield* getFiles(res);
} else {
yield res;
}
}
}
const rename = (oldPath, newPath) => exec(`git mv ${oldPath} ${newPath}`);
(async () => {
for await (const originalFilePath of getFiles(DIRECTORY)) {
const parts = originalFilePath.split('.');
if (parts[parts.length - 1] !== 'md') continue;
parts[parts.length - 1] = 'mdx';
const newFilePath = parts.join('.');
rename(originalFilePath, newFilePath);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment