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

[Xen-changelog] [xen-unstable] docs: generate an index for the html output



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1322576247 0
# Node ID b30064469a0355cbec71983b16139df19d0d6dca
# Parent  faa863f0343f5e6e7dc813227bfd03a8cd04bfe7
docs: generate an index for the html output

nb: I'm not a Perl wizard...

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r faa863f0343f -r b30064469a03 docs/INDEX
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/INDEX        Tue Nov 29 14:17:27 2011 +0000
@@ -0,0 +1,5 @@
+misc/hvm-emulated-unplug       Xen HVM emulated device unplug protocol
+
+# These are not all that useful anymore, hide them from the index
+interface/index                        NO-INDEX
+user/index                     NO-INDEX
diff -r faa863f0343f -r b30064469a03 docs/Makefile
--- a/docs/Makefile     Tue Nov 29 14:17:27 2011 +0000
+++ b/docs/Makefile     Tue Nov 29 14:17:27 2011 +0000
@@ -45,7 +45,7 @@
 pdf: $(DOC_PDF)
 
 .PHONY: html
-html: $(DOC_HTML)
+html: $(DOC_HTML) html/index.html
 
 .PHONY: txt
 txt: $(DOC_TXT)
@@ -128,6 +128,9 @@
        $< 1>/dev/null 2>/dev/null ; else \
        echo "latex2html not installed; skipping $*."; fi
 
+html/index.html: $(DOC_HTML) ./gen-html-index INDEX
+       perl -w -- ./gen-html-index -i INDEX html $(DOC_HTML)
+
 html/%.html: %.markdown
        @$(INSTALL_DIR) $(@D)
        @set -e ; if which $(MARKDOWN) 1>/dev/null 2>/dev/null; then \
diff -r faa863f0343f -r b30064469a03 docs/gen-html-index
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/docs/gen-html-index       Tue Nov 29 14:17:27 2011 +0000
@@ -0,0 +1,136 @@
+#!/usr/bin/env perl
+
+#
+# Generate indexes for html documentation
+#
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+use IO::File;
+use File::Basename;
+use List::MoreUtils qw/ uniq /;
+
+Getopt::Long::Configure('bundling');
+
+@ARGV >= 2 or die;
+
+our @docs;
+our @dirs;
+our %index;
+
+our $outdir;
+
+GetOptions("i=s" => sub { read_index(@_);} )
+    or die;
+
+($outdir,@docs) = @ARGV;
+
+sub write_file ($$) {
+    my ($opath, $odata) = @_;
+    print STDOUT "Writing: $opath\n";
+    my $out = new IO::File "$opath.new", '>' or die "$opath $!";
+    print $out $odata or die $!;
+    rename "$opath.new", "$opath" or die "$opath $!";
+}
+
+sub make_page ($$$) {
+    my ($file,$title,$content) = @_;
+    my $o = '';
+    my $h1;
+    if ( $title eq "" )
+    {
+        $title = $h1 = "Xen Documentation";
+    }
+    else
+    {
+        $h1 = "<a href=\"../index.(?:html|txt)\">Xen Documentation</a> - 
$title";
+        $title = "Xen Documentation - $title";
+    }
+    $o .= <<END;
+<html><head><title>$title</title></head>
+<body>
+<h1>$h1</h1>
+<ul>
+$content
+</ul>
+</body></html>
+END
+    write_file($file, $o);
+}
+
+sub make_linktext ($) {
+    my ($l) = @_;
+    return "$1($2)" if $l =~ m,^man/(.*)\.([0-9].*)\.html,;
+    $l =~ s/.(html)$//g;
+    return $index{$l} if exists $index{$l};
+    return basename($l);
+}
+
+sub make_link ($$) {
+    my ($ref,$base) = @_;
+
+    my $txt = make_linktext($ref);
+    $ref = basename($ref) if $base;
+
+    return "<li><a href=\"$ref\">$txt</a></li>\n";
+}
+
+sub make_links ($$@) {
+    my ($dir,$base,@docs) = @_;
+    my $idx = '';
+    foreach my $of (sort { $a cmp $b } @docs) {
+        $idx .= make_link($of,$base);
+    }
+    return $idx;
+}
+
+sub read_index ($$) {
+    my ($opt, $val) = @_;
+    my $idx = new IO::File "$val", '<' or die "$val $!";
+    while ($_ = $idx->getline()) {
+       s/^\s+//;
+       s/\s+$//;
+       next if m/^\#/;
+       next unless m/\S/;
+       m/^(\S+)\s+(\S.*)$/ or die;
+        $index{$1} = $2;
+    }
+}
+
+for (@docs) { s,^\Q$outdir\E/,, }
+
+@docs = grep { -e "$outdir/$_" && (make_linktext($_) ne "NO-INDEX") } @docs;
+
+my $top = '';
+
+foreach my $od (sort { $a cmp $b } uniq map { dirname($_) } @docs) {
+    my @d = (grep /^\Q$od\E/, @docs);
+    if ( @d == 1 and $d[0] eq "$od/index.html" )
+    {
+        $top .= "<li><a href=\"${od}/index.html\">${od}/index.html</a></li>\n";
+    }
+    else
+    {
+       my $links = make_links($od,0,@d);
+       $top .= <<END;
+<li><a href=\"${od}/index.html\">$od</a></li>
+<ul>
+$links
+</ul>
+END
+
+       $links = make_links($od,1,@d);
+        my $idx = '';
+       $idx .= <<END;
+<li>$od</li>
+<ul>
+$links
+</ul>
+END
+        make_page("$outdir/$od/index.html", $od, $idx);
+    }
+}
+
+make_page("$outdir/index.html", "", $top);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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