67 lines
1.4 KiB
Raku
67 lines
1.4 KiB
Raku
#!/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 {
|
|
$<date> = [$<y>=[\d**4] '-' $<m>=[\d**2] '-' $<d>=[\d**2]]
|
|
}
|
|
|
|
my $date = $cwd.match(&isodate)<date> // Date.today.yyyy-mm-dd;
|
|
my $name = $*CWD.basename.subst(/^<isodate> <[\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<VISUAL> // %*ENV<EDITOR> // 'nano';
|
|
run $editor, $output unless $no-edit;
|