Skip to content

Instantly share code, notes, and snippets.

@adufilie
Last active August 16, 2017 03:09
Show Gist options
  • Save adufilie/071062ff7434e486c3d78cedd0d36237 to your computer and use it in GitHub Desktop.
Save adufilie/071062ff7434e486c3d78cedd0d36237 to your computer and use it in GitHub Desktop.
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