1 |
#!/usr/local/bin/perl -w |
#!/usr/bin/perl -w |
2 |
use strict; |
use strict; |
3 |
use File::Find; |
use File::Find; |
4 |
use Getopt::Long; |
use Getopt::Long; |
7 |
my $collection; # name which will be inserted |
my $collection; # name which will be inserted |
8 |
my $path_add; # add additional info in path |
my $path_add; # add additional info in path |
9 |
my $verbose; |
my $verbose; |
10 |
|
my $exclude; |
11 |
|
my $skip_output; |
12 |
|
|
13 |
#$verbose = 1; |
#$verbose = 1; |
14 |
|
|
17 |
"path=s" => \$path_add, |
"path=s" => \$path_add, |
18 |
"verbose!" => \$verbose, |
"verbose!" => \$verbose, |
19 |
"debug!" => \$verbose, |
"debug!" => \$verbose, |
20 |
|
"exclude=s" => \$exclude, |
21 |
|
"skipoutput!" => \$skip_output, |
22 |
); |
); |
23 |
|
|
24 |
my $dir = shift @ARGV || die "usage: $0 [dir]"; |
my $dir = shift @ARGV || die "usage: $0 [dir]"; |
42 |
sub dump_contents($$$) { |
sub dump_contents($$$) { |
43 |
my ($contents,$mtime,$path) = @_; |
my ($contents,$mtime,$path) = @_; |
44 |
|
|
45 |
return if (! $contents); # don't die on empty files |
return unless ($contents); # don't die on empty files |
46 |
|
|
47 |
|
if ($exclude && $path =~ m/$exclude/i) { |
48 |
|
print STDERR "skip: $path\n" if ($verbose); |
49 |
|
return; |
50 |
|
} |
51 |
|
|
52 |
use bytes; |
use bytes; |
53 |
my $size = length $contents; |
my $size = length $contents; |
54 |
|
|
55 |
print STDERR " [$size]" if ($verbose); |
print STDERR " [$size]" if ($verbose); |
56 |
|
|
57 |
|
return if ($skip_output); |
58 |
|
|
59 |
# Output the document (to swish) |
# Output the document (to swish) |
60 |
print <<EOF; |
print <<EOF; |
61 |
Path-Name: $path |
Path-Name: $path |
62 |
Content-Length: $size |
Content-Length: $size |
63 |
Last-Mtime: $mtime |
Last-Mtime: $mtime |
64 |
Document-Type: HTML |
Document-Type: html* |
65 |
|
|
66 |
EOF |
EOF |
67 |
print $contents; |
print $contents; |
73 |
my $path = $_; |
my $path = $_; |
74 |
my $contents; |
my $contents; |
75 |
|
|
76 |
|
return if (-l $path); |
77 |
|
|
78 |
if ($pdftotext && -f $path && $path =~ m/\.pdf$/i) { |
if ($pdftotext && -f $path && $path =~ m/\.pdf$/i) { |
79 |
|
|
80 |
print STDERR "$path {converting}" if ($verbose); |
print STDERR "$path {converting}" if ($verbose); |
89 |
} |
} |
90 |
close(F); |
close(F); |
91 |
|
|
92 |
|
return if (! $html); |
93 |
|
|
94 |
|
my $file_only = $path; |
95 |
|
$file_only =~ s/^.*\/([^\/]+)$/$1/g; |
96 |
|
|
97 |
my ($pre_html,$pages,$post_html) = ('<html><head><title>$path :: page ##page_nr##</title></head><body><pre>',$html,'</pre></body></html>'); |
my ($pre_html,$pages,$post_html) = ('<html><head><title>$path :: page ##page_nr##</title></head><body><pre>',$html,'</pre></body></html>'); |
98 |
|
|
99 |
($pre_html,$pages,$post_html) = ($1,$2,$3) if ($html =~ m/^(<html>.+<pre>)(.+)(<\/pre>.+)$/si); |
($pre_html,$pages,$post_html) = ($1,$2,$3) if ($html =~ m/^(<html>.+?<pre>)(.+)(<\/pre>.+?)$/si); |
100 |
|
|
101 |
$pre_html =~ s/<title>(.+?)<\/title>/<title>$1 :: page ##page_nr##<\/title>/si; |
if ($collection) { |
102 |
|
$pre_html =~ s/<title>(.+?)<\/title>/<title>$collection :: page ##page_nr##<\/title>/si; |
103 |
|
} else { |
104 |
|
$pre_html =~ s/<title>(.+?)<\/title>/<title>$1 :: page ##page_nr##<\/title>/si || |
105 |
|
$pre_html =~ s/<title><\/title>/<title>$file_only :: page ##page_nr##<\/title>/si; |
106 |
|
} |
107 |
|
|
108 |
my $page_nr = 1; |
my $page_nr = 1; |
109 |
foreach my $page (split(/\f/,$pages)) { |
foreach my $page (split(/\f/s,$pages)) { |
110 |
|
print STDERR " $page_nr" if ($verbose); |
111 |
my $pre_tmp = $pre_html; |
my $pre_tmp = $pre_html; |
112 |
$pre_tmp =~ s/##page_nr##/$page_nr<\/title>/s; |
$pre_tmp =~ s/##page_nr##/$page_nr<\/title>/s; |
113 |
dump_contents($pre_tmp . $page . $post_html,time(), $path); |
dump_contents($pre_tmp . $page . $post_html,time(), $path) if ($page !~ m/^\s*$/s); |
114 |
$page_nr++; |
$page_nr++; |
115 |
} |
} |
116 |
|
|
117 |
} else { |
} else { |
118 |
|
|
119 |
return if (! -f $path || ! m/\.html*$/i); |
return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i); |
120 |
|
|
121 |
# skip index files |
# skip index files |
122 |
return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i); |
return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i); |
124 |
open(F,"$path") || die "can't open file: $path"; |
open(F,"$path") || die "can't open file: $path"; |
125 |
print STDERR "$path" if ($verbose); |
print STDERR "$path" if ($verbose); |
126 |
while(<F>) { |
while(<F>) { |
127 |
$contents .= "$_"; |
$contents .= $_; |
128 |
} |
} |
129 |
$contents .= "\n\n"; |
$contents .= "\n\n"; |
130 |
|
|