Mailing List Archive

[PATCH 11 of 17 v3] docs: generate an index for the html output
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# 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@citrix.com>

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@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 11 of 17 v3] docs: generate an index for the html output [ In reply to ]
On Tue, Nov 29, Ian Campbell wrote:

> +use List::MoreUtils qw/ uniq /;

This adds a new requires of perl-List-MoreUtils.rpm for make docs.
I'm not sure wether such buildrequires need to be listed in the README,
but at least markdown is listed. I think it is recommended for make docs

Olaf

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 11 of 17 v3] docs: generate an index for the html output [ In reply to ]
On Wed, 2011-11-30 at 20:50 +0000, Olaf Hering wrote:
> On Tue, Nov 29, Ian Campbell wrote:
>
> > +use List::MoreUtils qw/ uniq /;
>
> This adds a new requires of perl-List-MoreUtils.rpm for make docs.
> I'm not sure wether such buildrequires need to be listed in the README,
> but at least markdown is listed. I think it is recommended for make docs

Lets just nuke the requirement, it's trivial to reimplement.

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1322731354 0
# Node ID faab9e3c36f0a4eaec7f2af5cad9d3c038ea489b
# Parent 89f7273681696022cc44db4f2ec5b22560482869
docs: implement uniq instead of depending on List::MoreUtils

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 89f727368169 -r faab9e3c36f0 docs/gen-html-index
--- a/docs/gen-html-index Thu Dec 01 08:51:35 2011 +0100
+++ b/docs/gen-html-index Thu Dec 01 09:22:34 2011 +0000
@@ -10,7 +10,6 @@ use warnings;
use Getopt::Long;
use IO::File;
use File::Basename;
-use List::MoreUtils qw/ uniq /;

Getopt::Long::Configure('bundling');

@@ -99,6 +98,12 @@ sub read_index ($$) {
}
}

+sub uniq (@) {
+ my %h;
+ foreach (@_) { $h{$_} = 1; }
+ return keys %h;
+}
+
for (@docs) { s,^\Q$outdir\E/,, }

@docs = grep { -e "$outdir/$_" && (make_linktext($_) ne "NO-INDEX") } @docs;



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 11 of 17 v3] docs: generate an index for the html output [ In reply to ]
Ian Campbell writes ("Re: [Xen-devel] [PATCH 11 of 17 v3] docs: generate an index for the html output"):
> docs: implement uniq instead of depending on List::MoreUtils

Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>

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