[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 4/9] docs/gen-html-index: Extract titles from HTML documents



Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Release-acked-by: Juergen Gross <jgross@xxxxxxxx>
Acked-by: Lars Kurth <lars.kurth@xxxxxxxxxx>
(cherry picked from commit 7782db9260d4c6499458de4e8d9866bc0427e143)

[ Combined with: ]

docs/gen-html-index: Make HTML::TreeBuilder::XPath optional again

7782db9260d4 "docs/gen-html-index: Extract titles from HTML documents"
requires HTML::TreeBuilder::XPath.

This is sadly not as widely available as I had hoped.  Work around
this problem by making the use of this module optional: instead of
`use'ing at the toplevel, we `require' it in the eval.  If it's not
present, then the title is simply not extracted and the filename is
used as before, which is tolerable.

Also add some debugging.

Reported-by: Doug Goldstein <cardoe@xxxxxxxxxx>
Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Reviewed-by: Doug Goldstein <cardoe@xxxxxxxxxx>
Tested-by: Doug Goldstein <cardoe@xxxxxxxxxx>
(cherry picked from commit 16fb4b5a9a79f95df17f10ba62e9f44d21cf89b5)
---
 docs/gen-html-index | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/docs/gen-html-index b/docs/gen-html-index
index e9792bf..410674e 100644
--- a/docs/gen-html-index
+++ b/docs/gen-html-index
@@ -20,8 +20,10 @@ our @dirs;
 our %index;
 
 our $outdir;
+our $debug;
 
-GetOptions("i=s" => sub { read_index(@_);} )
+GetOptions("i=s" => sub { read_index(@_);},
+           "D" => \$debug)
     or die;
 
 ($outdir,@docs) = @ARGV;
@@ -64,6 +66,20 @@ sub make_linktext ($) {
     return "$1($2)" if $l =~ m,^man/(.*)\.([0-9].*)\.html,;
     $l =~ s/.(?:html|txt)$//g;
     return $index{$l} if exists $index{$l};
+
+    my $from_html;
+    eval {
+        require HTML::TreeBuilder::XPath;
+        my $tree = new HTML::TreeBuilder::XPath;
+        my $f = "$outdir/$l.html";
+        open F, '<', $f or die "$l $f $!";
+        $tree->parse_file(\*F) or die;
+        close F;
+        $from_html = $tree->findvalue("/html/head/title");
+    };
+    print "$l: get title: $@" if $@ && $debug;
+    return $from_html if $from_html;
+
     return basename($l);
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.