Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.7 KiB

  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. wrt-display - print static HTML from wrt entries
  5. =head1 USAGE
  6. wrt display new # newest entries
  7. wrt display all # table of contents for all dated entries
  8. wrt display 2016/4/1 # a specific date
  9. wrt display 2016/4 # all entries for a specific month
  10. wrt display 2016/4 # summary of entries for a year
  11. wrt display fulltext # complete text of archive
  12. wrt display feed # Atom feed of most recent month's entries
  13. # Take list of entries to display from standard input:
  14. echo 2016/4/1 | wrt display --stdin
  15. # Specify a different config file:
  16. wrt display --config ./wrt.json ...
  17. # Display help:
  18. wrt display --help
  19. =head1 DESCRIPTION
  20. C<wrt-display> displays HTML for the given entry or entries in the current wrt
  21. repository to F<stdout>. Entries may be specified by date or name.
  22. =head2 Special Entries
  23. B<new> will return entries for the most recent month.
  24. B<feed> will return an Atom feed for the most recent month.
  25. B<all> will return a table-of-contents for all date-based entries.
  26. B<fulltext> will return the full content of all date-based entries in the
  27. archive.
  28. Months in the form of B<yyyy/mm> will return all entries for that month.
  29. Years in the form of B<yyyy> will return a summary of entries for the year.
  30. Detailed documentation can be found in the L<App::WRT> man page or at
  31. L<https://github.com/brennen/wrt>.
  32. =head1 LICENSE
  33. wrt is free software; you can redistribute it and/or modify
  34. it under the terms of the GNU General Public License as published by
  35. the Free Software Foundation; either version 2 of the License, or
  36. (at your option) any later version.
  37. =head1 AUTHOR
  38. Brennen Bearnes
  39. =cut
  40. use 5.10.0;
  41. use strict;
  42. use warnings;
  43. no warnings 'uninitialized';
  44. # use Data::Dumper;
  45. use Getopt::Long;
  46. use Pod::Usage;
  47. use App::WRT;
  48. # Handle options, including help generated from the POD above. See:
  49. # - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options
  50. # - https://metacpan.org/pod/Pod::Usage
  51. # - http://michael.thegrebs.com/2014/06/08/Pod-Usage/
  52. my $from_stdin = 0;
  53. my $config_file = 'wrt.json';
  54. GetOptions(
  55. stdin => \$from_stdin,
  56. config => \$config_file,
  57. help => sub { pod2usage(0) },
  58. ) or pod2usage(2);
  59. unless (-e $config_file) {
  60. die "No wrt config file found. Tried: $config_file";
  61. }
  62. my $w = App::WRT::new_from_file($config_file);
  63. # With --stdin, take names of entries to display from standard input, one line
  64. # per name. Otherwise, take names from arguments.
  65. my @to_display = ();
  66. if ($from_stdin) {
  67. while (my $entry = <>) {
  68. chomp($entry);
  69. push @to_display, $entry;
  70. }
  71. } else {
  72. (@to_display) = @ARGV;
  73. }
  74. print $w->display(@to_display);
  75. exit(0);