build_index.pl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. use FindBin::libs;
  6. use Trog::Data;
  7. use Trog::Config;
  8. use Trog::SQLite::TagIndex;
  9. =head1 SYNOPSIS
  10. Rebuild the FlatFile model's tag index and route table, data/posts.db, from the
  11. posts in data/files.
  12. Use this to build the index after you import posts, otherwise it is not needed:
  13. tCMS keeps the index up to date as it writes posts, so the only time it gets out
  14. of step with the flat files is when something other than tCMS put them there.
  15. The SQLite model keeps its tags and routes with the posts, and has no separate
  16. index. On a site served from it, this says so and changes nothing.
  17. =head2 USAGE
  18. bin/build_index.pl
  19. Takes no arguments, and must be run from the tCMS root, as the data paths in
  20. the configuration are relative to it.
  21. Safe to re-run. It empties the index first and builds it again, in one
  22. transaction, so tags and routes that no post has any more are gone afterwards.
  23. =cut
  24. my $data = Trog::Data->new( Trog::Config::get() );
  25. if ( !$data->isa('Trog::Data::FlatFile') ) {
  26. say "This site serves from " . ref($data) . ", which has no separate index. Nothing to do.";
  27. exit 0;
  28. }
  29. Trog::SQLite::TagIndex::rebuild($data);