[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 11 of 17 v3] docs: generate an index for the html output
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1322576247 0 # Node ID 37b46c492f8ac8d356b2b88e8ff00d359443163a # Parent 334a8606c849cbaff265181241714e527d5ecba4 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 334a8606c849 -r 37b46c492f8a 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 334a8606c849 -r 37b46c492f8a 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 @@ 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 + 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 334a8606c849 -r 37b46c492f8a 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-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |