Created
May 24, 2016 04:40
-
-
Save handlename/7b3b7661b14f641e6b23f3ea6c27f97a to your computer and use it in GitHub Desktop.
hatenablog2hugo to my hugo
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/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Path::Class qw{dir}; | |
my $root = dir("."); | |
for my $year ($root->children) { | |
next if ! $year->is_dir; | |
next if $year->basename =~ /\d{8}/; | |
for my $month ($year->children) { | |
for my $day ($month->children) { | |
my $dirname = $year->basename . $month->basename . $day->basename; | |
# mkdir $dirname; | |
for my $article ($day->children) { | |
my $org = $article->absolute; | |
my $dst = $root->subdir($dirname)->file($article->basename)->absolute; | |
warn $org . " -> " . $dst; | |
# rename $org, $dst; | |
} | |
$day->remove; | |
} | |
$month->remove; | |
} | |
$year->remove; | |
} | |
for my $year ($root->children) { | |
next if ! $year->is_dir; | |
my $org = $year->absolute; | |
my $dst = $org; | |
$dst =~ s/(....)(..)(..)$/$1-$2-$3/; | |
warn $org . " -> " . $dst; | |
rename $org, $dst; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment