]> git.proxmox.com Git - pve-docs.git/blob - gen-index-includes.pl
add external metric server to sysadmin.adoc
[pve-docs.git] / gen-index-includes.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use JSON;
6 use IO::File;
7 use Data::Dumper;
8
9 my $fh = IO::File->new("link-refs.json", "r") ||
10 die "unable to open 'link-refs.json' - $!\n";
11
12 my $data_str = "";
13 while (<$fh>) { $data_str .= $_; }
14 my $fileinfo = decode_json($data_str);
15
16 my $cmd = shift;
17
18 die "missing command name" if !$cmd;
19 die "too many arguments" if scalar(@ARGV);
20
21
22 #print Dumper($fileinfo);
23
24 if ($cmd eq 'chapter-table') {
25 print '[width="100%",options="header"]' . "\n";
26 print "|====\n";
27 print "|Title|Link\n";
28 my $filelist = $fileinfo->{outfile}->{default};
29 foreach my $sourcefile (sort keys %$filelist) {
30 my $target = $filelist->{$sourcefile};
31 next if $target eq 'pve-admin-guide.html';
32 my $title = $fileinfo->{titles}->{default}->{$sourcefile} ||
33 die "not title for '$sourcefile'";
34 print "|$title|link:$target\[\]\n";
35 }
36 print "|====\n";
37
38 } elsif ($cmd =~ m/^man([158])page-table$/) {
39 my $section = $1;
40 print '[width="100%",cols="5*d",options="header"]' . "\n";
41 print "|====\n";
42 print "|Name 3+|Title|Link\n";
43 my $filelist = $fileinfo->{outfile}->{manvolnum};
44 foreach my $manpage (sort keys %$filelist) {
45 next if $section ne $fileinfo->{mansection}->{manvolnum}->{$manpage};
46 my $mantitle = $fileinfo->{titles}->{manvolnum}->{$manpage} ||
47 die "not manual title for '$manpage'";
48 my $title = $fileinfo->{titles}->{default}->{$manpage} ||
49 die "not title for '$manpage'";
50
51 # hack - remove command name prefix from titles
52 $title =~ s/^[a-z]+\s*-\s*//;
53
54 my $target = $filelist->{$manpage};
55 print "|$mantitle 3+|$title|link:$target.html\[$target\]\n\n";
56 }
57 print "|====\n";
58 } else {
59 die "unknown command '$cmd'\n";
60 }