--- trunk/spider/filter.pm 2004/01/20 18:40:06 51
+++ trunk/spider/filter.pm 2004/01/23 13:10:40 56
@@ -37,6 +37,55 @@
}
+ # is second argument collection?
+ my $collection = shift || return $contents;
+
+ # construct new title (from various parts of DocBook if available)
+ my $new_title;
+
+ if ($contents =~ m,,is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ } else {
+ if ($contents =~ m,
([^<]+),is) {
+ $new_title = $1;
+ } elsif ($contents =~ m,]*>([^<]+),is) {
+ $new_title = $1;
+ }
+ }
+
+ if ($new_title) {
+ # check if new title is same as collection name
+ my ($a,$b) = ($new_title,$collection);
+ $a =~ s/([^a-zA-Z])+/ /gs;
+ $b =~ s/([^a-zA-Z])+/ /gs;
+ if ($a =~ m/$b/i) {
+ $new_title = $collection;
+ } else {
+ $new_title = "$collection :: $new_title";
+ }
+ } else {
+ # fall-back to collection title
+ $new_title = $collection;
+ }
+
+ $new_title =~ s/\s\s+/ /g;
+
+ if ($contents =~ s,(.*),$new_title,is) {
+ print STDERR "replace title '$1' with '$new_title'\n";
+ } else {
+ print STDERR "adding new title '$new_title'\n";
+ # try to insert after , or at top
+ $contents =~ s,(),$1$new_title,is ||
+ $contents =~ s,(),$1$new_title,is ||
+ $contents =~ s,^,$new_title,;
+ }
+
return $contents;
}