add --subdirs

This commit is contained in:
rhiannon morris 2023-11-21 23:23:00 +01:00
parent 4242dfe096
commit 36a3338ff2

View file

@ -22,6 +22,8 @@ unit sub MAIN(
Bool :v(:$verbose) = False,
#| out dir, default ./out
IO(Str) :o(:$outdir) = 'out'.IO,
#| use a subdirectory for each site
Bool :d(:$subdirs) = False,
#| defaults to all *.png & *.jpg files in the current dir
*@files,
);
@ -49,7 +51,10 @@ for @files { die "$_ is not a regular file" unless .f; }
# running imagemagick (and oxipng sometimes) 🪄
sub convert($in, $name, $size, $format) {
my $out = $outdir.child($in.basename).extension("$name.$format");
my $out = $subdirs
?? $outdir.child($name).child($in.basename).extension("$format")
!! $outdir.child($in.basename).extension("$name.$format");
cmd <mkdir -p>, $out.dirname;
cmd <convert>, $in, '-resize', $size, '-quality', $quality, $out;
cmd <oxipng -q>, $out if $format == png;
}
@ -76,7 +81,6 @@ sub parallel(@vals, &f) {
@tasks».result;
}
cmd <mkdir -p>, $outdir;
my @todo = @files X @sites;
parallel @todo, -> ($file, % (:$name, :$format, :$size)) {