From 3019857cc95e67ed45f8c05f24c9271a01f5885a Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 29 Nov 2011 14:17:27 +0000 Subject: docs: generate an index for the html output nb: I'm not a Perl wizard... Signed-off-by: Ian Campbell Committed-by: Ian Jackson Acked-by: Ian Jackson --- docs/gen-html-index | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 docs/gen-html-index (limited to 'docs/gen-html-index') diff --git a/docs/gen-html-index b/docs/gen-html-index new file mode 100644 index 0000000000..06d7f62edb --- /dev/null +++ b/docs/gen-html-index @@ -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 = "Xen Documentation - $title"; + $title = "Xen Documentation - $title"; + } + $o .= <$title + +

$h1

+
    +$content +
+ +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 "
  • $txt
  • \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 .= "
  • ${od}/index.html
  • \n"; + } + else + { + my $links = make_links($od,0,@d); + $top .= <$od +
      +$links +
    +END + + $links = make_links($od,1,@d); + my $idx = ''; + $idx .= <$od +
      +$links +
    +END + make_page("$outdir/$od/index.html", $od, $idx); + } +} + +make_page("$outdir/index.html", "", $top); -- cgit v1.2.3