/[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 65 by dpavlin, Wed Mar 17 12:19:14 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 45  sub filter { Line 48  sub filter {
48    
49          if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) {          if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) {
50                  $new_title = $1;                  $new_title = $1;
51          } elsif ($contents =~ m,<h\d\sclass="docPartTitle"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docPartTitle"[^>]*>(.+?)<\1>,is) {
52                  $new_title = $1;                  $new_title = $2;
53          } elsif ($contents =~ m,<h\d\sclass="docChapterTitle"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docChapterTitle"[^>]*>(.+?)<\1>,is) {
54                  $new_title = $1;                  $new_title = $2;
55          } elsif ($contents =~ m,<h\d\sclass="docSection1Title"[^>]*>([^<]+)</h\d>,is) {          } elsif ($contents =~ m,<(h\d)\sclass="docSection1Title"[^>]*>(.+?)<\1>,is) {
56                  $new_title = $1;                  $new_title = $2;
57            } elsif ($contents =~ m,<(h\d)\sclass="chapter"[^>]*>(.+?)<\1>,is) {
58                    $new_title = $2;
59            } elsif ($contents =~ m,<(h\d)\sclass="sect1"[^>]*>(.+?)<\1>,is) {
60                    $new_title = $2;
61          } else {          } else {
62                  if ($contents =~ m,<title>([^<]+)</title>,is) {                  if ($contents =~ m,<title>([^<]+)</title>,is) {
63                          $new_title = $1;                          $new_title = $1;
# Line 60  sub filter { Line 67  sub filter {
67          }          }
68    
69          if ($new_title) {          if ($new_title) {
70                    # nuke html in title
71                    $new_title =~ s/<br>\s+/: /gs;
72                    $new_title =~ s/<\/*[^>]+>//gs;
73            
74                  # check if new title is same as collection name                  # check if new title is same as collection name
75                  my ($a,$b) = ($new_title,$collection);                  my ($a,$b) = ($new_title,$collection);
76                  $a =~ s/([^a-zA-Z])+/ /gs;                  $a =~ s/([^a-zA-Z])+/ /gs;
# Line 76  sub filter { Line 87  sub filter {
87    
88          $new_title =~ s/\s\s+/ /g;          $new_title =~ s/\s\s+/ /g;
89    
90          if ($contents =~ s,<title>(.*)</title>,$new_title,is) {          if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) {
91                  print STDERR "replace title '$1' with '$new_title'\n";                  print STDERR "replace title '$1' with '$new_title'\n" if ($verbose);
92          } else {          } elsif (
93                  print STDERR "adding new title '$new_title'\n";                          # try to insert after <head>, <html> or at top
                 # try to insert after <head>, <html> or at top  
94                  $contents =~ s,(<head>),$1<title>$new_title</title>,is ||                  $contents =~ s,(<head>),$1<title>$new_title</title>,is ||
95                  $contents =~ s,(<html>),$1<title>$new_title</title>,is ||                  $contents =~ s,(<html>),$1<title>$new_title</title>,is ||
96                  $contents =~ s,^,<title>$new_title</title>,;                          $contents =~ s,^,<title>$new_title</title>, ) {
97                    print STDERR "adding new title '$new_title'\n" if ($verbose);
98          }          }
99    
100          return $contents;          return $contents;

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

  ViewVC Help
Powered by ViewVC 1.1.26