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.

100 lines
2.4 KiB

v6.0.0: expand EntryStore, test more, cache harder This commit is something of a hairball, the result of evenings-and-weekends hacking building up a set of changes that got out of hand in parallel. If I had the energy to spare, I would break it apart into semantically-related changes, but I don't - and I suppose all this crap being rolled together is at least reflective of how the code was written. These changes are really half-finished, at best. Eventual goals: - App::WRT shouldn't directly touch the filesystem - App::WRT::EntryStore should model the entry archive completely - App::WRT::Renderer should say what to write to the publication directory - This one's a maybe: Filesystem interaction should pass through App::WRT::FileIO or something like it so that EntryStore and Renderer can be more usefully tested, with mocked writes (maybe) I do think this represents an inflection point in the long, silly life of this program: It includes a handful of new tests, and a number of the code changes were in turn easy to make because the test suite begins to model the code in a useful way. It's less and less necessary to run wrt against the p1k3.com archives to be sure that I haven't trashed something. Breaking changes to note: - Will no longer render HTML for nonexistent entries - Months and years which are flatfiles or contain an index are handled differently, albeit less brokenly - EntryStore includes index files in its overall list of entries (this seems to break less than I thought), which trickles out to bin/wrt-ls Overall changes herein: - App::WRT::Date - Move month_name() in here from App::WRT, add tests. - App::WRT::EntryStore - Hash file types for entries (directory or flatfile) - Use keys of file type hash for complete list of entries. - has_prop($entry, $property) - is_dir($entry), is_file($entry), is_extant($entry) - parent_of($entry) - has_index($entry) - Make EntryStore cache whether a file is a flatfile or a directory, as well as its existence, in a single hash. - Include index flatfiles in @source_files for use by has_index() - Various tests. - App::WRT::FileIO - Still duplicates a bunch of shit from Util, so that needs sorted. - App::WRT::Renderer - Convert to a proper class. - Add experimental FileIO class to use in Renderer (imperfect, tricky, still thinking about this). The idea is to separate out the concerns of reading and writing the filesystem. - App::WRT - Refactor display() and improve tests - Use "@entries" instead of "@options" for clarity - Handle entry names that might evaluate as false - Test running display() without any params - Rename expand_option() -> expand_alias(), refactor - Use EntryStore::has_prop() to detect wrt-noexpand.prop - year(), month(), entry() partially rewritten to use EntryStore - year() should handle months which are a flatfile - Refactor icon_markup() to use is_file() / is_dir() / is_extant(), add tests. - Add subtitle to feeds - bin/wrt-ls is now a "modulino" with tests - bin/display errors on non-existent entries - Build.PL - Remove bogus XML::Feed dependency
5 years ago
  1. #!/usr/bin/env perl
  2. =pod
  3. =head1 NAME
  4. wrt-render-all - utility for rendering static HTML files from wrt entries
  5. =head1 USAGE
  6. wrt render-all
  7. wrt render-all --config ./wrt.json ...
  8. wrt render-all --help
  9. =head1 DESCRIPTION
  10. Renders all entries in the current wrt archive to the C<publish_dir> specified
  11. in the configuration file (normally F<wrt.json>). By default, this is
  12. F<./public>.
  13. Detailed documentation can be found in the L<App::WRT> man page or at
  14. L<https://code.p1k3.com/gitea/brennen/wrt>.
  15. =head1 LICENSE
  16. wrt is free software; you can redistribute it and/or modify
  17. it under the terms of the GNU General Public License as published by
  18. the Free Software Foundation; either version 2 of the License, or
  19. (at your option) any later version.
  20. =head1 AUTHOR
  21. Brennen Bearnes <code@p1k3.com>
  22. =cut
  23. use 5.10.0;
  24. use strict;
  25. use warnings;
  26. no warnings 'uninitialized';
  27. use Getopt::Long;
  28. use Pod::Usage;
  29. use Time::HiRes;
  30. use App::WRT;
  31. use App::WRT::FileIO;
  32. use App::WRT::Renderer;
  33. my $start_time = [Time::HiRes::gettimeofday()];
  34. # If invoked directly from the command-line, caller() will return undef.
  35. # Execute main() with a callback to print output directly, a FileIO object,
  36. # and a copy of our real @ARGV:
  37. if (not caller()) {
  38. my $output = sub { say @_; };
  39. my $io = App::WRT::FileIO->new();
  40. main($output, $io, @ARGV);
  41. exit(0);
  42. }
  43. # main() takes an output callback, a FileIO object or equivalent, and an @ARGV
  44. # to pass in to GetOptionsFromArray(). This allows relatively simple
  45. # integration tests to be written. See also: t/bin-wrt-render-all.t
  46. sub main {
  47. my ($output, $io, @local_argv) = @_;
  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 $config_file = 'wrt.json';
  53. GetOptions(
  54. 'config=s' => \$config_file,
  55. help => sub { pod2usage(0) },
  56. ) or pod2usage(2);
  57. unless (-e $config_file) {
  58. die "No wrt config file found. Tried: $config_file";
  59. }
  60. my $wrt = App::WRT::new_from_file($config_file);
  61. # This expects a callback to handle logging output and a callback to handle
  62. # file writing:
  63. my $renderer = App::WRT::Renderer->new(
  64. $wrt,
  65. $output,
  66. $io
  67. );
  68. $renderer->render();
  69. $output->(
  70. "elapsed: " . Time::HiRes::tv_interval($start_time) . " seconds"
  71. );
  72. }
  73. 1;