#!/usr/bin/env raku #| generate gallery info file unit sub MAIN( Str :o($output) = 'info.yaml', #= output file Bool :f($force) = False, #= overwrite an existing file Bool :N($no-edit) = False, #= don't open editor after *@files, #= files to list (default all images except thumb.*) ); my $cwd = $*CWD.basename; my token isodate { $ = [$=[\d**4] '-' $=[\d**2] '-' $=[\d**2]] } my $date = $cwd.match(&isodate) // Date.today.yyyy-mm-dd; my $name = $*CWD.basename.subst(/^ <[\w]>*\-/, '').trans('-' => ' '); sub image($path) { qq:to/END/.chomp - path: $path.basename() desc: > ... nsfw: false warning: "" END } sub is-image($_) { /\. [jpg | png | webp | gif | svg]$/ and not /^thumb\./ } my @images = @files ?? @filesĀ».IO !! $*CWD.dir(test => &is-image).sort; die "no images found in $*CWD" unless @images; my $thumb-line = do given $*CWD.dir: test => /^thumb \./ { when ([*]) { "thumb: $_[0].basename()" } default { "" } }; # spurt 'info.yaml', qq:to/END/; my $yaml = qq:to/END/; date: $date title: $name tags: null images: {@images.map(&image).join: "\n"} $thumb-line bg: noborder desc: | ... END if $output eq '-' { print $yaml; } elsif $output.IO.e and not $force { say "$output already exists, use -f if you're sure"; exit 1; } else { spurt $output, $yaml; } my $editor = %*ENV // %*ENV // 'nano'; run $editor, $output unless $no-edit;