Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Scripts to rename posts filenames
require 'vendor/autoload.php';
$renamed_posts = [];
foreach (new DirectoryIterator('source/_posts') as $file) {
if (!$file->isFile()) {
$filename = $file->getBasename('.md');
if (preg_match('/^\d{4}-\d{2}-\d{2}/', $filename)) {
$filename =substr($filename, 10);
$new_filename = str_slug($filename) . '.md';
$renamed_posts[$file->getFilename()] = $new_filename;
echo 'git mv ' . $file->getRealPath() . ' source/_posts/' . $new_filename . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.