8 |
$contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*/noindex\s*-->,,isg; |
$contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*/noindex\s*-->,,isg; |
9 |
$contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*index\s*-->,,isg; |
$contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*index\s*-->,,isg; |
10 |
# this will remove all script from indexing content |
# this will remove all script from indexing content |
11 |
$contents =~ s,<script>.+?</script>,,isg; |
$contents =~ s,<script[^>]*>.+?</script>,,isg; |
12 |
# remap Windows charset to ISO-8859-2 |
# remap Windows charset to ISO-8859-2 |
13 |
$contents =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
$contents =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2 |
14 |
# this will fix badly formatted html in form: |
# this will fix badly formatted html in form: |
36 |
$contents =~ s,(<title>)([^<]+)(</title>),$1$2: $title$3,gsi if ($title); |
$contents =~ s,(<title>)([^<]+)(</title>),$1$2: $title$3,gsi if ($title); |
37 |
|
|
38 |
} |
} |
39 |
|
|
40 |
|
# is second argument collection? |
41 |
|
my $collection = shift || return $contents; |
42 |
|
|
43 |
|
# construct new title (from various parts of DocBook if available) |
44 |
|
my $new_title; |
45 |
|
|
46 |
|
if ($contents =~ m,<!--SafTocEntry="([^"]+)"-->,is) { |
47 |
|
$new_title = $1; |
48 |
|
} elsif ($contents =~ m,<h\d\sclass="docPartTitle"[^>]*>([^<]+)</h\d>,is) { |
49 |
|
$new_title = $1; |
50 |
|
} elsif ($contents =~ m,<h\d\sclass="docChapterTitle"[^>]*>([^<]+)</h\d>,is) { |
51 |
|
$new_title = $1; |
52 |
|
} elsif ($contents =~ m,<h\d\sclass="docSection1Title"[^>]*>([^<]+)</h\d>,is) { |
53 |
|
$new_title = $1; |
54 |
|
} else { |
55 |
|
if ($contents =~ m,<title>([^<]+)</title>,is) { |
56 |
|
$new_title = $1; |
57 |
|
} elsif ($contents =~ m,<h\d[^>]*>([^<]+)</h\d>,is) { |
58 |
|
$new_title = $1; |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
|
if ($new_title) { |
63 |
|
# check if new title is same as collection name |
64 |
|
my ($a,$b) = ($new_title,$collection); |
65 |
|
$a =~ s/([^a-zA-Z])+/ /gs; |
66 |
|
$b =~ s/([^a-zA-Z])+/ /gs; |
67 |
|
if ($a =~ m/$b/i) { |
68 |
|
$new_title = $collection; |
69 |
|
} else { |
70 |
|
$new_title = "$collection :: $new_title"; |
71 |
|
} |
72 |
|
} else { |
73 |
|
# fall-back to collection title |
74 |
|
$new_title = $collection; |
75 |
|
} |
76 |
|
|
77 |
|
$new_title =~ s/\s\s+/ /g; |
78 |
|
|
79 |
|
if ($contents =~ s,<title>(.*)</title>,$new_title,is) { |
80 |
|
print STDERR "replace title '$1' with '$new_title'\n"; |
81 |
|
} else { |
82 |
|
print STDERR "adding new title '$new_title'\n"; |
83 |
|
# try to insert after <head>, <html> or at top |
84 |
|
$contents =~ s,(<head>),$1<title>$new_title</title>,is || |
85 |
|
$contents =~ s,(<html>),$1<title>$new_title</title>,is || |
86 |
|
$contents =~ s,^,<title>$new_title</title>,; |
87 |
|
} |
88 |
|
|
89 |
return $contents; |
return $contents; |
90 |
} |
} |
91 |
|
|