79d105ea8fead34c896a84144baf81e479d7834f
[openafs.git] / doc / man-pages / generate-html
1 #!/usr/bin/perl -w
2 package OpenAFS::HTML;
3
4 use strict;
5 use vars qw(@ISA);
6
7 use Pod::Simple::Search;
8 @ISA = qw(Pod::Simple::HTML);
9
10 sub do_man_link {
11     my ($self, $token) = @_;
12     my $page = $token->attr('to');
13     my ($name, $section) = ($page =~ /^([^\(]+)\((\d+)\)$/);
14     return unless $name;
15     my @url = ('..', $section, $name);
16     return join ('/', map { $self->pagepath_url_escape ($_) } @url)
17         . $Pod::Simple::HTML::HTML_EXTENSION;
18 }
19
20 sub VERSION () { '1.0' }
21
22 $Pod::Simple::HTML::Tagmap{'item-bullet'} = '<li><p>';
23 $Pod::Simple::HTML::Tagmap{'/item-bullet'} = '</p></li>';
24 $Pod::Simple::HTML::Tagmap{'item-number'} = '<li><p>';
25 $Pod::Simple::HTML::Tagmap{'/item-number'} = '</p></li>';
26
27 package main;
28
29 use strict;
30
31 use File::Copy;
32 use Pod::Simple::HTMLBatch;
33
34 our $HEADER = <<'EOH';
35 <html>
36 <head>
37   <title>OpenAFS Reference Manual</title>
38   <link rel="stylesheet" title="style" type="text/css" href="style.css" media="all">
39 </head>
40 <body class='contentspage'>
41 <h1>OpenAFS Reference Manual</h1>
42 EOH
43
44 our %HEADINGS = (1 => 'User Commands',
45                  5 => 'Configuration and Data Files',
46                  8 => 'Administrator Commands');
47
48 # Scan all of the POD files and build a list of section, name, and short
49 # description, returning that as an array.
50 sub scan_names {
51     my @index;
52     for my $dir (qw(pod1 pod5 pod8)) {
53         my $section = $dir;
54         $section =~ s/^pod//;
55         opendir (D, $dir) or die "Cannot open $dir: $!\n";
56         for my $file (sort grep { !/^\./ && !/CVS/ } readdir D) {
57             open (F, "$dir/$file") or die "Cannot open $dir/$file: $!\n";
58             my ($name, $desc);
59             local $_;
60             while (<F>) {
61                 last if /^=head1/ && !/^=head1\s+NAME\b/;
62                 next unless /\s+-\s+/;
63                 ($name, $desc) = split (/\s+-\s+/, $_, 2);
64             }
65             unless ($name) {
66                 warn "$dir/$file: cannot find NAME section, skipping\n";
67             }
68             my $page = $file;
69             $page =~ s/\.pod$//;
70             push (@index, [ $section, $name, $page, $desc ]);
71         }
72         closedir D;
73     }
74     return @index;
75 }
76
77 unless (-d 'html') {
78     mkdir ('html', 0755) or die "Cannot create html directory: $!\n";
79 }
80 for my $dir (qw(pod1 pod5 pod8)) {
81     my $section = $dir;
82     $section =~ s/^pod//;
83     mkdir ("html/$section", 0755) unless -d "html/$section";
84
85     my $conv = Pod::Simple::HTMLBatch->new;
86     $conv->verbose (0);
87     $conv->index (undef);
88     $conv->contents_file (undef);
89     $conv->add_css ('../style.css', 1);
90     $conv->css_flurry (0);
91     $conv->javascript_flurry (0);
92     $conv->html_render_class ('OpenAFS::HTML');
93     $conv->batch_convert ($dir, "html/$section");
94 }
95 copy ('style.css', 'html/style.css') or die "Cannot copy style.css: $!\n";
96
97 open (INDEX, '> html/index.html')
98     or die "Cannot create html/index.html: $!\n";
99 print INDEX $HEADER;
100 print INDEX "<table>\n";
101 my @index = scan_names;
102 my $current;
103 for my $entry (@index) {
104     my ($section, $name, $page, $desc) = @$entry;
105     for ($name, $desc) {
106         s/&/&gt;/g;
107         s/</&lt;/g;
108         s/>/&gt;/g;
109     }
110     if (!$current || $section != $current) {
111         print INDEX qq(<tr><td>&nbsp;</td></tr>\n);
112         print INDEX qq(<tr class="heading"><th colspan="2">);
113         print INDEX qq($HEADINGS{$section}</th></tr>\n);
114         $current = $section;
115     }
116     print INDEX qq(<tr><td><a href="$section/$page.html">$name</a></td>);
117     print INDEX qq(<td>$desc</td></tr>\n);
118 }
119 print INDEX "</table>\n</body>\n</html>\n";