Browse Source

bin/wrt-feed: add --json option; handle @local_argv correctly

Now prints JSON versions of feeds when given --json.

Also handles flags correctly by using @local_argv inside main() rather
than the unmodified @ARGV - a bug lingering from copypasta of wrt-display
code.
master
Brennen Bearnes 1 year ago
parent
commit
e863f439e3
2 changed files with 18 additions and 5 deletions
  1. +1
    -0
      bin/wrt
  2. +17
    -5
      bin/wrt-feed

+ 1
- 0
bin/wrt View File

@ -11,6 +11,7 @@ wrt - WRiting Tool, a static site/blog generator and related utilites
wrt init # Initialize a wrt repository
wrt display # Print HTML for entries
wrt feed # Print feeds for entries
wrt render-all # Render all defined entries to filesystem
wrt ls # List entries in repository
wrt config # Display current configuration


+ 17
- 5
bin/wrt-feed View File

@ -4,15 +4,17 @@
=head1 NAME
wrt-feed - print a feed from given wrt entries
wrt-feed - print an Atom or JSON feed from given wrt entries
=head1 USAGE
# Print most recent entries:
wrt feed
wrt feed --json
# Print entries for a specific month:
wrt feed 2019/11
wrt feed --json 2019/11
=head1 DESCRIPTION
@ -63,11 +65,13 @@ sub main {
# - https://metacpan.org/pod/Pod::Usage
# - http://michael.thegrebs.com/2014/06/08/Pod-Usage/
my $from_stdin = 0;
my $print_json = 0;
my $config_file = 'wrt.json';
GetOptionsFromArray(
\@local_argv,
stdin => \$from_stdin,
json => \$print_json,
'config=s' => \$config_file,
help => sub { pod2usage(0) },
@ -88,8 +92,8 @@ sub main {
chomp($entry);
push @to_display, $entry;
}
} elsif (@ARGV) {
(@to_display) = @ARGV;
} elsif (@local_argv) {
(@to_display) = @local_argv;
}
my (@expanded_to_display) = map { $w->expand_alias($_) } @to_display;
@ -103,9 +107,17 @@ sub main {
}
if (@expanded_to_display) {
$output->( $w->feed_print(@expanded_to_display) );
if ($print_json) {
$output->( $w->feed_print_json(@expanded_to_display) );
} else {
$output->( $w->feed_print(@expanded_to_display) );
}
} else {
$output->( $w->feed_print_recent() );
if ($print_json) {
$output->( $w->feed_print_json_recent() );
} else {
$output->( $w->feed_print_recent() );
}
}
return 0;


Loading…
Cancel
Save