App-PFT
view release on metacpan or search on metacpan
bin/pft-grab view on Meta::CPAN
destination.
This command outputs the I<Markdown> code for linking the grabbed content
item in a PFT page. The output can be inserted in the PFT entry.
The output will be consistent with the attachment/picture choice: if
B<--picture> is specified, the Markdown notation for including a picture
will be used, otherwise the syntax for links will be used. See L<EXAMPLE>.
Users of the I<ViM> editor may find useful to invoke this command from
within the editor as follows:
:read ! pft grab [options] file [file...]
=head1 OPTIONS
=over
=item B<--today> | B<-t>
Store the file inside a content directory named after the current day. This
is meant to avoid name conflict with previously stored attachments or
pictures having the same name (see L<EXAMPLE>).
=item B<--picture> | B<-p>
Store the files into the C<I<ROOT>/content/pics> directory and output the
Markdown code required to show it as a picture.
Note that no check is performed on the file format to verify it is actually
a picture.
=item B<--rename>=I<name> | B<-r> I<name>
Rename the file. The alternate file name supplied with this option must
explicitly set the extension, if an extension is desired. Supplying the
wrong extension will not imply a format change.
This option is not allowed if multiple files are grabbed with the same
command.
=item B<--year>=I<Y> | B<-y> I<Y>
When using B<--today>, overload year with I<Y>. Implies B<--today>.
=item B<--month>=I<M> | B<-m> I<M>
When using B<--today>, overload month with I<M>. Implies B<--today>.
=item B<--day>=I<D> | B<-d> <D>
When using B<--today>, overload day with I<D>. Implies B<--today>.
=item B<--help> | B<-h>
Show this help.
=back
=head1 EXAMPLE
$ pft grab /tmp/tux.png
[tux.png]: :attach:tux.png
$ pft grab /tmp/tux.png --picture

$ pft grab /tmp/tux.png --picture --today

$ pft grab --picture http://example.com/picture.png

=head1 SEE ALSO
L<pft-make(1)>
=cut
use strict;
use warnings;
use feature qw/say/;
use File::Spec::Functions qw/catfile catdir abs2rel/;
use File::Path qw/make_path/;
use File::Basename qw/basename/;
use File::Copy;
use Encode;
use Encode::Locale;
use Getopt::Long;
Getopt::Long::Configure ("bundling");
use PFT::Tree;
use URI;
use LWP::Simple;
my %date;
my %opts = (
dst => 'a',
date => 0,
);
GetOptions(
'year|y=i' => \$date{year},
'month|m=s' => \$date{month},
'day|d=i' => \$date{day},
'today|t!' => \$opts{date_prefix},
'picture|p!' => sub { $opts{dst} = 'p' },
#'attach|a!' => sub { $opts{dst} = 'a' },
'rename|r=s' => \$opts{rename},
'help|h' => sub {
pod2usage
-exitval => 1,
-verbose => 2,
-input => App::PFT::help_of 'grab',
}
) or exit 1;
@ARGV or do {
say STDERR 'Any file?';
exit 1;
};
@ARGV > 1 and $opts{rename} and do {
say STDERR '--rename is not allowed with multiple files';
exit 1;
};
my $content = eval{ PFT::Tree->new->content } or do {
( run in 1.175 second using v1.01-cache-2.11-cpan-df04353d9ac )