/[swish]/trunk/spider/filter.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/spider/filter.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 56 by dpavlin, Fri Jan 23 13:10:40 2004 UTC revision 71 by dpavlin, Sat Apr 3 15:15:36 2004 UTC
# Line 1  Line 1 
1  sub filter {  sub filter {
2          my $contents = shift || return;          my $contents = shift || return;
3    
4            my $verbose = 0;
5            
6          # if you don't want content to be indexed, include it in          # if you don't want content to be indexed, include it in
7          # <noindex> foobar </noindex> tags or surround it with comments          # <noindex> foobar </noindex> tags or surround it with comments
8          # <!-- noindex --> foobar <!-- /noindex -->          # <!-- noindex --> foobar <!-- /noindex -->
# Line 19  sub filter { Line 22  sub filter {
22          # remove comments between <html> and <head> texi2html inserts them          # remove comments between <html> and <head> texi2html inserts them
23          # there and swish can't find document title then (libxml or swish bug?)          # there and swish can't find document title then (libxml or swish bug?)
24          while ($contents =~ s/(<html>.*)<!--.*?-->(.*<head>)/$1$2/msi) { };          while ($contents =~ s/(<html>.*)<!--.*?-->(.*<head>)/$1$2/msi) { };
25            
26            # remove empty lines before/after <html>
27            $contents =~ s/^\s+(<html>)/$1/is;
28            $contents =~ s/(<\/html>)\s+$/$1/is;
29            # remove cr
30            $contents =~ s/\r//gs;
31    
32            # remove SQL Magazine header and footer
33            $contents =~ s/<!-- begin topnav area -->.+?<!-- end topnav area -->/<\/table>/is;
34            $contents =~ s/<!--Begin Footer-->.+?<\/table>/<\/table>/is;
35    
36          # remote TPJ left column          # remote TPJ left column
37          if ($contents =~ s,<!-- BEGIN LEFT SIDE BAR CELL -->.+?<!-- END LEFT SIDE BAR CELL -->,,isg) {          if ($contents =~ s,<!-- BEGIN LEFT SIDE BAR CELL -->.+?<!-- END LEFT SIDE BAR CELL -->,,isg) {
# Line 45  sub filter { Line 58  sub filter {
58    
59          if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) {          if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) {
60                  $new_title = $1;                  $new_title = $1;
61          } elsif ($contents =~ m,<h\d\sclass="docPartTitle"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docPartTitle"[^>]*>(.+?)<\1>,is) {
62                  $new_title = $1;                  $new_title = $2;
63          } elsif ($contents =~ m,<h\d\sclass="docChapterTitle"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docChapterTitle"[^>]*>(.+?)<\1>,is) {
64                  $new_title = $1;                  $new_title = $2;
65          } elsif ($contents =~ m,<h\d\sclass="docSection1Title"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docSection1Title"[^>]*>(.+?)<\1>,is) {
66                  $new_title = $1;                  $new_title = $2;
67            } elsif ($contents =~ m,<(h\d)\sclass="chapter"[^>]*>(.+?)<\1>,is) {
68                    $new_title = $2;
69            } elsif ($contents =~ m,<(h\d)\sclass="sect1"[^>]*>(.+?)<\1>,is) {
70                    $new_title = $2;
71          } else {          } else {
72                  if ($contents =~ m,<title>([^<]+)</title>,is) {                  if ($contents =~ m,<title>([^<]+)</title>,is) {
73                          $new_title = $1;                          $new_title = $1;
# Line 60  sub filter { Line 77  sub filter {
77          }          }
78    
79          if ($new_title) {          if ($new_title) {
80                    # nuke html in title
81                    $new_title =~ s/<br>\s+/: /gs;
82                    $new_title =~ s/<\/*[^>]+>//gs;
83            
84                  # check if new title is same as collection name                  # check if new title is same as collection name
85                  my ($a,$b) = ($new_title,$collection);                  my ($a,$b) = ($new_title,$collection);
86                  $a =~ s/([^a-zA-Z])+/ /gs;                  $a =~ s/([^a-zA-Z])+/ /gs;
# Line 76  sub filter { Line 97  sub filter {
97    
98          $new_title =~ s/\s\s+/ /g;          $new_title =~ s/\s\s+/ /g;
99    
100          if ($contents =~ s,<title>(.*)</title>,$new_title,is) {          if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) {
101                  print STDERR "replace title '$1' with '$new_title'\n";                  print STDERR "replace title '$1' with '$new_title'\n" if ($verbose);
102            } elsif ($contents =~ s,(<head>),$1<title>$new_title</title>,is) {
103                    print STDERR "adding title '$new_title' after <head>\n" if ($verbose);
104            
105            } elsif ($contents =~ s,(<html>),$1<head><title>$new_title</title></head>,is) {
106                    print STDERR "adding title '$new_title' after <html>\n" if ($verbose);
107    
108            } elsif ($contents =~ s,^,<title>$new_title</title>,)  {
109                    print STDERR "adding new title '$new_title'\n" if ($verbose);
110          } else {          } else {
111                  print STDERR "adding new title '$new_title'\n";                  print STDERR "WARNING: filter couldn't add new title '$new_title' anywhere!";
                 # try to insert after <head>, <html> or at top  
                 $contents =~ s,(<head>),$1<title>$new_title</title>,is ||  
                 $contents =~ s,(<html>),$1<title>$new_title</title>,is ||  
                 $contents =~ s,^,<title>$new_title</title>,;  
112          }          }
113    
114          return $contents;          return $contents;

Legend:
Removed from v.56  
changed lines
  Added in v.71

  ViewVC Help
Powered by ViewVC 1.1.26