[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 11 of 15 v2] docs: generate an index for the html output
On Fri, 2011-11-25 at 18:43 +0000, Roger Pau Monnà wrote: > > diff -r ddeac8b237e4 -r 00ea49f77bdc docs/gen-html-index > > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > > +++ b/docs/gen-html-index Fri Nov 25 14:34:21 2011 +0000 > > @@ -0,0 +1,136 @@ > > +#!/usr/bin/perl -w > > What about using the following: > > #!/usr/bin/env perl > use warnings; [...] Ian J suggested to use "/usr/bin/env perl" and to invoke the script in the Makefile with perl -w directly (in reality only the Makefile invocation matters). So this is what the following replacement patch does: 8<------------------------------------ # HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1322559594 0 # Node ID f2be6269d5e23dfc71c627aef588adddc6a0da8a # Parent ddeac8b237e4f71d05c817fa8432417886e7e202 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 ddeac8b237e4 -r f2be6269d5e2 docs/INDEX --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/INDEX Tue Nov 29 09:39:54 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 ddeac8b237e4 -r f2be6269d5e2 docs/Makefile --- a/docs/Makefile Fri Nov 25 11:53:06 2011 +0000 +++ b/docs/Makefile Tue Nov 29 09:39:54 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 ddeac8b237e4 -r f2be6269d5e2 docs/gen-html-index --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/gen-html-index Tue Nov 29 09:39:54 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 |