[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 13 of 17] docs: generate an index for the html output
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1321542075 0 # Node ID 8f2404eef8fac8020528b408b3a958d81cbb73c0 # Parent c1f8406da50743cd0597b93c4b5b8b6ff03ede42 docs: generate an index for the html output nb: I'm not a Perl wizard... Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> diff -r c1f8406da507 -r 8f2404eef8fa docs/INDEX --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/INDEX Thu Nov 17 15:01:15 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 c1f8406da507 -r 8f2404eef8fa docs/Makefile --- a/docs/Makefile Thu Nov 17 14:54:38 2011 +0000 +++ b/docs/Makefile Thu Nov 17 15:01:15 2011 +0000 @@ -45,7 +45,7 @@ ps: $(DOC_PS) pdf: $(DOC_PDF) .PHONY: html -html: $(DOC_HTML) +html: $(DOC_HTML) html/index.html .PHONY: txt txt: $(DOC_TXT) @@ -128,6 +128,9 @@ html/%/index.html: src/%.tex $< 1>/dev/null 2>/dev/null ; else \ echo "latex2html not installed; skipping $*."; fi +html/index.html: $(DOC_HTML) ./gen-html-index INDEX + ./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 c1f8406da507 -r 8f2404eef8fa docs/gen-html-index --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/gen-html-index Thu Nov 17 15:01:15 2011 +0000 @@ -0,0 +1,129 @@ +#!/usr/bin/perl -w + +# +# 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) = @_; + 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\">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 + print STDERR "Writing: $file\n"; + 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/#.*$//; + m/./ or next; + m/([^\t]+)\t+(.*)/ or die; + $index{$1} = $2; + } +} + +for (@docs) { s,^${outdir}/,, } + +@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 /^$od/, @docs); + if ( $#d == 0 and $d[0] eq "$od/index.html" ) + { + $top .= "<li><a href=\"${od}/index.html\">${od}/index.html</a></li>\n"; + } + else + { + $top .= "<li><a href=\"${od}/index.html\">$od</a></li>\n"; + $top .= "<ul>\n"; + $top .= make_links($od,0,@d); + $top .= "</ul>\n"; + + my $idx = ''; + $idx .= "<li>$od</li>\n"; + $idx .= "<ul>\n"; + $idx .= make_links($od,1,@d); + $idx .= "</ul>\n"; + make_page("$outdir/$od/index.html", $od, $idx); + } +} + +make_page("$outdir/index.html", "", $top); _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |