Instantly share code, notes, and snippets.

Embed
What would you like to do?
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