/[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

Annotation of /trunk/spider/filter.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 46 - (hide annotations)
Sat Jan 17 23:57:55 2004 UTC (20 years, 2 months ago) by dpavlin
File size: 1591 byte(s)
- moved text/html content filtering to filter.pm to faciliate code re-use
- added progspider which can be used with -S prog to crawl files and
  use filtering subroutines

1 dpavlin 46 sub filter {
2     my $contents = shift || return;
3     # if you don't want content to be indexed, include it in
4     # <noindex> foobar </noindex> tags or surround it with comments
5     # <!-- noindex --> foobar <!-- /noindex -->
6     # <!-- noindex --> foobar <!-- index --> (also supported by swish)
7     $contents =~ s,<noindex>.+?</noindex>,,isg;
8     $contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*/noindex\s*-->,,isg;
9     $contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*index\s*-->,,isg;
10     # this will remove all script from indexing content
11     $contents =~ s,<script>.+?</script>,,isg;
12     # remap Windows charset to ISO-8859-2
13     $contents =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
14     # this will fix badly formatted html in form:
15     # <head><title>some text</title
16     # ></head>
17     # which will confuse indexer (or libxml2?)
18     $contents =~ s/[\n\r]^(>)/$1\n/msg;
19     # remove comments between <html> and <head> texi2html inserts them
20     # there and swish can't find document title then (libxml or swish bug?)
21     while ($contents =~ s/(<html>.*)<!--.*?-->(.*<head>)/$1$2/msi) { };
22    
23     # remote TPJ left column
24     if ($contents =~ s,<!-- BEGIN LEFT SIDE BAR CELL -->.+?<!-- END LEFT SIDE BAR CELL -->,,isg) {
25     my $title;
26     # extract title and add to title
27     if ($contents =~ m,<!-- the article goes here -->\s*<h2[^>]*>(.+?)</h2>,si) {
28     $title = $1;
29     } elsif ($contents =~ m,<h1[^>]*>(.+?)</h1>,is) {
30     $title = $1;
31     } elsif ($contents =~ m,<h2[^>]*>(.+?)</h2>,is) {
32     $title = $1;
33     } else {
34     $title = "no detail title";
35     }
36     $contents =~ s,(<title>)([^<]+)(</title>),$1$2: $title$3,gsi if ($title);
37    
38     }
39     return $contents;
40     }
41    
42     1;

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26