/[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 51 by dpavlin, Tue Jan 20 18:40:06 2004 UTC revision 57 by dpavlin, Sun Jan 25 16:49:50 2004 UTC
# Line 1  Line 1 
1  sub filter {  sub filter {
2          my $contents = shift || return;          my $contents = shift || return;
3    
4    #       my $verbose = 1;
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 37  sub filter { Line 40  sub filter {
40    
41          }          }
42    
43            # is second argument collection?
44            my $collection = shift || return $contents;
45    
46            # construct new title (from various parts of DocBook if available)
47            my $new_title;
48    
49            if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) {
50                    $new_title = $1;
51            } elsif ($contents =~ m,<h\d\sclass="docPartTitle"[^>]*>([^<]+)</h\d>,is) {
52                    $new_title = $1;
53            } elsif ($contents =~ m,<h\d\sclass="docChapterTitle"[^>]*>([^<]+)</h\d>,is) {
54                    $new_title = $1;
55            } elsif ($contents =~ m,<h\d\sclass="docSection1Title"[^>]*>([^<]+)</h\d>,is) {
56                    $new_title = $1;
57            } else {
58                    if ($contents =~ m,<title>([^<]+)</title>,is) {
59                            $new_title = $1;
60                    } elsif ($contents =~ m,<h\d[^>]*>([^<]+)</h\d>,is) {
61                            $new_title = $1;
62                    }
63            }
64    
65            if ($new_title) {
66                    # check if new title is same as collection name
67                    my ($a,$b) = ($new_title,$collection);
68                    $a =~ s/([^a-zA-Z])+/ /gs;
69                    $b =~ s/([^a-zA-Z])+/ /gs;
70                    if ($a =~ m/$b/i) {
71                            $new_title = $collection;
72                    } else {
73                            $new_title = "$collection :: $new_title";
74                    }
75            } else {
76                    # fall-back to collection title
77                    $new_title = $collection;
78            }
79    
80            $new_title =~ s/\s\s+/ /g;
81    
82            if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) {
83                    print STDERR "replace title '$1' with '$new_title'\n" if ($verbose);
84            } elsif (
85                            # try to insert after <head>, <html> or at top
86                    $contents =~ s,(<head>),$1<title>$new_title</title>,is ||
87                    $contents =~ s,(<html>),$1<title>$new_title</title>,is ||
88                            $contents =~ s,^,<title>$new_title</title>, ) {
89                    print STDERR "adding new title '$new_title'\n" if ($verbose);
90            }
91    
92          return $contents;          return $contents;
93  }  }
94    

Legend:
Removed from v.51  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26