Skip to content

Instantly share code, notes, and snippets.

@jasonmccreary
Created January 4, 2019 18:31
Show Gist options
  • Save jasonmccreary/2eef6508bba04703ce202612f76ececd to your computer and use it in GitHub Desktop.
Save jasonmccreary/2eef6508bba04703ce202612f76ececd to your computer and use it in GitHub Desktop.
Scripts to rename posts filenames
<?php
require 'vendor/autoload.php';
$renamed_posts = [];
foreach (new DirectoryIterator('source/_posts') as $file) {
if (!$file->isFile()) {
continue;
}
$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