#!/usr/bin/perl -w
use strict;
use warnings;
use File::Find;
my $dir = shift || die "failed to specify directory";
my $pat = qr!([^<]+)!i; #" for vim
if ( -f $dir ) {
warn "Indexing [$dir] as a single file\n";
index_path( $dir );
exit;
}
find( \&process_doc, $dir );
# swish-e -S program to index the HTML docs in sections.
sub process_doc {
my $file = $_;
my $path = $File::Find::name;
my $dir = $File::Find::dir;
return if -d;
return unless /\.html$/; # how's that!
return if /^\./;
return if /robots\.txt/;
return if /\.css$/;
return if $dir =~ m!/search!;
return if $dir =~ m!/graphics!;
index_path( $path );
}
sub index_path {
my ( $path ) = @_;
unless ( open( FH, "<$path" ) ) {
warn "Failed to open file - [$path]: $!\n";
return;
}
local $/;
index_doc( $path, );
}
sub index_doc {
my ($name, $doc) = @_;
my @sections = split /$pat/, $doc;
die unless @sections;
# Get rid of the first part
shift @sections;
my ( $title ) = $doc =~ m[([^<]+)]is;
$title ||= "Swish-e Documentation";
$title =~ s/^Swish-e :: //;
while ( @sections ) {
my ( $section, $sec_text, $text ) = splice( @sections, 0, 3 );
output( $name, $section, $sec_text, $text, $title );
}
}
sub output {
my ( $name, $section, $sec_text, $text, $title ) = @_;
my $date = (stat $name)[9];
my $doc = <$title : $sec_text
$text