Created
May 7, 2014 14:36
-
-
Save chadluo/1bc88ccec974d65feaec to your computer and use it in GitHub Desktop.
rename Hexo md files to Jekyll style.
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
#!/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