Created
November 26, 2020 19:05
-
-
Save jankal/f039145d6285efb001bd60304e0a3445 to your computer and use it in GitHub Desktop.
Need to rename a lot of markdown files to slugs? - Worry no more.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const slugify = require('slugify'); | |
const directory = './content/articles'; | |
const files = fs.readdirSync(path.resolve(__dirname, directory)); | |
for (const file of files) { | |
if (file.endsWith('.md')) { | |
fs.rename( | |
path.resolve(__dirname, directory, file), | |
path.resolve( | |
__dirname, | |
directory, | |
slugify(file.substr(0, file.length - 3), { | |
lower: true, | |
strict: true, | |
locale: 'en' | |
}) + '.md' | |
), | |
(err) => { | |
console.error(err); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment