Last active
August 16, 2017 03:09
-
-
Save adufilie/071062ff7434e486c3d78cedd0d36237 to your computer and use it in GitHub Desktop.
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
use autodie; | |
use feature "say"; | |
use Cwd 'abs_path'; | |
use File::Find; | |
sub noExt | |
{ | |
shift =~ /([^\/]+)\.[^.]+$/; | |
return $1; | |
} | |
sub findByDir | |
{ | |
my $path = shift; | |
my %dirs; | |
find(sub{ | |
my $name = $File::Find::name; | |
my $dir = $File::Find::dir; | |
$dirs{$name} = [] if -d; | |
push(@{$dirs{$dir}}, $name) if -f; | |
}, $path); | |
return %dirs; | |
} | |
my %filesByDir = findByDir("."); | |
for my $dir (sort keys %filesByDir) | |
{ | |
my @files = sort {(lc noExt $a) cmp (lc noExt $b)} @{$filesByDir{$dir}}; | |
my @images = grep {/\.(jpg|png)$/} @files; | |
say '<h1>'.($dir =~ s%^\./?%%r).'</h1>' if $#images >= 0; | |
say '<img src="'.$_.'" width="244" height="361">' for @images; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment