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 --> |
79 |
|
|
80 |
$new_title =~ s/\s\s+/ /g; |
$new_title =~ s/\s\s+/ /g; |
81 |
|
|
82 |
if ($contents =~ s,<title>(.*)</title>,$new_title,is) { |
if ($contents =~ s,<title>(.*)</title>,<title>$new_title</title>,is) { |
83 |
print STDERR "replace title '$1' with '$new_title'\n"; |
print STDERR "replace title '$1' with '$new_title'\n" if ($verbose); |
84 |
} else { |
} elsif ( |
85 |
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 |
|
86 |
$contents =~ s,(<head>),$1<title>$new_title</title>,is || |
$contents =~ s,(<head>),$1<title>$new_title</title>,is || |
87 |
$contents =~ s,(<html>),$1<title>$new_title</title>,is || |
$contents =~ s,(<html>),$1<title>$new_title</title>,is || |
88 |
$contents =~ s,^,<title>$new_title</title>,; |
$contents =~ s,^,<title>$new_title</title>, ) { |
89 |
|
print STDERR "adding new title '$new_title'\n" if ($verbose); |
90 |
} |
} |
91 |
|
|
92 |
return $contents; |
return $contents; |