Skip to content

Instantly share code, notes, and snippets.

@chadluo
Created May 7, 2014 14:36
Show Gist options
  • Save chadluo/1bc88ccec974d65feaec to your computer and use it in GitHub Desktop.
Save chadluo/1bc88ccec974d65feaec to your computer and use it in GitHub Desktop.
rename Hexo md files to Jekyll style.
#!/usr/bin/perl
use strict;
use warnings;
opendir(D,".");
my @files = readdir(D);
closedir(D);
foreach my $file (@files) {
next if (not $file =~ /\.md$/);
open FILE, $file or die $!;
my $date = "";
my $plink = $file;
my $newname;
while (<FILE>) {
if ($_ =~ /^\s*date\:\s(\d{4}-\d{2}-\d{2})/) {
$date = $1."-";
}
if ($_ =~ /^\s*permalink\:\s(\w+)/) {
$plink = $1.".md";
}
}
$newname = $date.$plink;
print $newname."\n";
rename $file, $newname;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment