Created
January 4, 2019 18:31
-
-
Save jasonmccreary/2eef6508bba04703ce202612f76ececd to your computer and use it in GitHub Desktop.
Scripts to rename posts filenames
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
<?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