diff options
Diffstat (limited to 'katana.raku')
| -rwxr-xr-x | katana.raku | 106 |
1 files changed, 10 insertions, 96 deletions
diff --git a/katana.raku b/katana.raku index eee5927..59202a8 100755 --- a/katana.raku +++ b/katana.raku @@ -2,96 +2,12 @@ use v6.d; use lib 'lib'; -use Katana::Tag; -sub prefix:<❱>(*@args) { - say "❱ {@args}"; - my \proc = run @args, :out, :err; - .say if .chars > 0 - for proc.out.slurp(:close), proc.err.slurp(:close); -} - -sub prefix:<⁉>(*@args) { ❱ @args unless @args[*-1].IO.f } - -sub read-exif-info(Str $file) { - my %exif; - my \proc = run 'exiftool', $file, :out; - for proc.out.slurp(:close).split("\n") -> $line { - my ($key, $val) = $line.split(':')[0,1]; - next unless defined $val; - %exif{$key.trim} = $val.trim; - } - return %exif; -} - -class Image { - has Str $.basename; - has Str $!source; - has Str $!dist-dir; - has Str $.camera; - - submethod BUILD(IO::Path :$source, Str :$dist-dir) { - $!basename = $source.basename; - $!source = $source.path; - $!dist-dir = $dist-dir; - } - - method generate(Int :$thumb-geometry, Str :$bg-blur) { - my $thumb = "$!dist-dir/thumb/{$.basename}"; - ⁉ [|<convert -auto-orient -geometry>, $thumb-geometry, $!source, $thumb]; - - my $blur = "$!dist-dir/blur/{$.basename}"; - ⁉ [|<convert -flip -geometry>, $thumb-geometry/4, '-blur', $bg-blur, $thumb, $blur]; - - my $large = "$!dist-dir/large/{$.basename}"; - ⁉ ['cp', $!source, $large]; - } - - method get-camera-model { - my %exif = read-exif-info "$!dist-dir/large/{$.basename}"; - my $make = %exif<Make> ?? %exif<Make> !! ''; - my $model = %exif{'Camera Model Name'} ?? %exif{'Camera Model Name'} !! ''; - $model ~~ s/$make //; # Don't stotter - $model = 'Unknown camera' if $model eq ''; - $!camera = "$make $model".trim; - } - - method tag(Str $class) { - "<img class='{$class}' src='./{$class}/{$.basename}' />" - } -} - -sub dist-dirs(Str \dist-dir --> List) { dist-dir <<~>> </large /blur /thumb> } - -sub ensure-directories(Str \dist-dir) { - mkdir dist-dir unless dist-dir.IO.d; - mkdir $_ unless .IO.d for dist-dirs dist-dir; -} - -sub walk-dir(Str \dir, :&onFile, :&onDir = sub (\dir) {} ) { - return unless dir.IO.d; - for dir(dir) -> $fh { - given $fh { - when .d { walk-dir $fh.path, :&onFile, :&onDir } - default { &onFile($fh.path) } - } - } - &onDir(dir); -} - -sub cleanup-nonexistent (Str \dist-dir, @images) { - my $basenames = set @images.map:{ $_.basename }; - walk-dir dist-dir, - onFile => sub (\file) { - unlink file if file.IO.basename ∉ $basenames - }; -} - -sub make-mr-proper(Str \dist-dir) { - walk-dir dist-dir, - onFile => sub (\file) { unlink file }, - onDir => sub (\dir) { rmdir dir }; -} +use Katana::Exec::Command; +use Katana::HTML::Generate; +use Katana::HTML::Tag; +use Katana::Image::Elem; +use Katana::Walk::Dir; sub camera-stats(@images) { my %cameras; @@ -126,19 +42,18 @@ multi MAIN( push @html-elems, Tag.new: name => 'title', text => $title; - recurse-tags $doctype, @html-elems; + generate-from-tags $doctype, @html-elems; - exit; my @images = dir($in-dir, test => { "$in-dir/$_".IO.f }).map:{ - Image.new: source => $_, :$dist-dir + Elem.new: source => $_, :$dist-dir }; say "Found {@images.elems} images"; @images = @images.pick: * if $randomize; - cleanup-nonexistent $dist-dir, @images; - make-mr-proper $dist-dir if $mr-proper; - ensure-directories $dist-dir; + dir-cleanup-nonexistent $dist-dir, @images; + dir-make-mr-proper $dist-dir if $mr-proper; + dir-ensure $dist-dir; @images.hyper(:$degree).map:{ .get-camera-model; @@ -147,4 +62,3 @@ multi MAIN( .say for camera-stats @images; } - |
