]>
Commit | Line | Data |
---|---|---|
aa99b349 DM |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
835dd63b DM |
5 | use Getopt::Long; |
6 | use File::Path; | |
7 | use File::Basename; | |
8 | use IO::File; | |
d77477d7 | 9 | use Cwd; |
835dd63b | 10 | |
aa99b349 DM |
11 | use JSON; |
12 | ||
034b35c8 DM |
13 | my $verbose; |
14 | my $keep_artifacts; | |
15 | ||
835dd63b DM |
16 | my $release = '@RELEASE@'; |
17 | ||
18 | my $clicmd = shift or | |
19 | die "no command specified\n"; | |
20 | ||
aa99b349 DM |
21 | my $data_str = ""; |
22 | while (<main::DATA>) { $data_str .= $_; } | |
23 | ||
24 | my $fileinfo = decode_json($data_str); | |
aa99b349 | 25 | |
835dd63b DM |
26 | my $tmpprefix = ".asciidoc-pve-tmp_"; |
27 | ||
28 | my $adoc_source_dir = "/usr/share/pve-doc-generator"; | |
29 | ||
30 | # inside pve-docs source dir? | |
31 | if (-f "attributes.txt" && -f "pve-admin-guide.adoc") { | |
32 | $adoc_source_dir = "." | |
33 | } | |
34 | ||
35 | my $prepared_files = {}; | |
36 | ||
4ff677c9 | 37 | my $man_target = 'man'; |
835dd63b DM |
38 | my $env_stack = []; |
39 | my $env_skip = 0; | |
40 | ||
a297b96e DM |
41 | my $online_help_links = { |
42 | 'pve_service_daemons' => { | |
43 | link => '/pve-docs/index.html#_service_daemons', | |
44 | title => 'Service Daemons', | |
45 | }, | |
46 | 'pve_documentation_index' => { | |
47 | link => '/pve-docs/index.html', | |
48 | title => 'Proxmox VE Documentation Index', | |
49 | }, | |
50 | 'pve_admin_guide' => { | |
51 | link => '/pve-docs/pve-admin-guide.html', | |
52 | title => 'Proxmox VE Administration Guide', | |
53 | }, | |
54 | }; | |
55 | ||
94a60df7 DM |
56 | sub debug { |
57 | my $msg = shift; | |
58 | ||
59 | return if !$verbose; | |
60 | ||
61 | print STDERR "asciidoc-pve: $msg\n"; | |
62 | } | |
63 | ||
835dd63b DM |
64 | sub push_environment { |
65 | my ($env, $skip) = @_; | |
66 | ||
67 | $skip = 1 if $env_skip; | |
68 | $skip = 0 if !defined($skip); | |
69 | ||
70 | push @$env_stack, [$env, $skip]; | |
71 | ||
72 | $env_skip = $skip; | |
73 | } | |
74 | ||
75 | sub pop_environment { | |
76 | my ($env) = @_; | |
77 | ||
78 | my $last_stack_entry = pop @$env_stack; | |
79 | die "unable to pop env '$env'" if !defined($last_stack_entry); | |
80 | ||
81 | my ($last_env, $skip) = @$last_stack_entry; | |
82 | die "environment missmatch (${last_env} != $env)\n" if $last_env ne $env; | |
83 | ||
84 | if (!scalar(@$env_stack)) { | |
85 | $env_skip = 0; | |
86 | } else { | |
87 | my (undef, $skip) = @{$env_stack->[-1]}; | |
88 | $env_skip = $skip; | |
89 | } | |
90 | } | |
91 | ||
034b35c8 DM |
92 | my $files_for_cleanup = []; |
93 | ||
17d8be0c DM |
94 | sub cleanup { |
95 | ||
034b35c8 DM |
96 | return if $keep_artifacts; |
97 | ||
98 | foreach my $file (@$files_for_cleanup) { | |
99 | unlink $file; | |
100 | } | |
17d8be0c DM |
101 | } |
102 | ||
835dd63b DM |
103 | sub replace_wiki_xref { |
104 | my ($blockid, $text) = @_; | |
105 | ||
106 | my $link = $fileinfo->{blockid_target}->{wiki}->{$blockid}; | |
45930831 | 107 | my $reftext = $fileinfo->{reftext}->{wiki}->{$blockid}; |
835dd63b DM |
108 | |
109 | die "unable to resolve wiki link (xref:$blockid)\n" | |
110 | if !defined($link); | |
111 | ||
45930831 DM |
112 | $text = $reftext if !length($text); |
113 | ||
c38115e9 | 114 | die "xref: no text for wiki link '$blockid'\n" if !$text; |
508e0012 | 115 | |
835dd63b DM |
116 | return "$link\[$text\]"; |
117 | } | |
118 | ||
c38115e9 DM |
119 | sub replace_default_xref { |
120 | my ($blockid, $text) = @_; | |
121 | ||
122 | my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; | |
123 | my $reftext = $fileinfo->{reftext}->{default}->{$blockid}; | |
124 | ||
125 | die "unable to resolve chapter link (xref:$blockid)\n" | |
126 | if !defined($link); | |
127 | ||
128 | $text = $reftext if !length($text); | |
129 | ||
130 | die "xref: no text for chapter link '$blockid'\n" if !$text; | |
131 | ||
132 | return "$link\[$text\]"; | |
133 | } | |
134 | ||
135 | sub replace_man_xref { | |
136 | my ($blockid, $text) = @_; | |
137 | ||
138 | my $link = $fileinfo->{blockid_target}->{manvolnum}->{$blockid}; | |
139 | my $reftext = $fileinfo->{reftext}->{manvolnum}->{$blockid}; | |
140 | ||
141 | die "unable to resolve man page link (xref:$blockid)\n" | |
142 | if !defined($link); | |
143 | ||
144 | $text = $reftext if !length($text); | |
145 | ||
146 | die "xref: no text for man page link '$blockid'\n" if !$text; | |
147 | ||
148 | my $section = $fileinfo->{mansection}->{manvolnum}->{$link}; | |
149 | die "link target is not a manual page" if !defined($section); | |
150 | ||
151 | ||
4ff677c9 | 152 | if ($man_target eq 'html') { |
c38115e9 DM |
153 | my $target = $link; |
154 | $target =~ s/\.adoc//; | |
155 | $target .= ".$section"; | |
156 | return "link:${target}.html#${blockid}\[$text\]"; | |
4ff677c9 | 157 | } elsif ($man_target eq 'man') { |
c38115e9 DM |
158 | my $command = $link; |
159 | $command =~ s/\.adoc//; | |
160 | return "\*${text}\* (man \*${command}\*($section))"; | |
4ff677c9 DM |
161 | } else { |
162 | die "internal error" | |
c38115e9 DM |
163 | } |
164 | } | |
165 | ||
a22a4a80 DM |
166 | sub replace_xref { |
167 | my ($env, $blockid, $text) = @_; | |
835dd63b | 168 | |
a22a4a80 DM |
169 | if ($env eq 'wiki') { |
170 | return replace_wiki_xref($blockid, $text); | |
c38115e9 | 171 | } elsif ($env eq 'manvolnum') { |
4ff677c9 DM |
172 | if (($man_target eq 'man') || ($man_target eq 'html')) { |
173 | return replace_man_xref($blockid, $text); | |
174 | } elsif ($man_target eq 'wiki') { | |
175 | return replace_wiki_xref($blockid, $text); | |
176 | } else { | |
177 | die "internal error" | |
178 | } | |
c38115e9 DM |
179 | } elsif ($env eq 'default') { |
180 | return replace_default_xref($blockid, $text); | |
a22a4a80 | 181 | } else { |
c38115e9 | 182 | die "internal error"; |
a22a4a80 DM |
183 | } |
184 | } | |
185 | ||
186 | sub prepare_adoc_file { | |
187 | my ($target_env, $filename, $attributes) = @_; | |
508e0012 | 188 | |
c38115e9 | 189 | return $prepared_files->{$filename} if defined($prepared_files->{$filename}); |
835dd63b | 190 | |
94a60df7 | 191 | debug("prepare $filename"); |
835dd63b | 192 | |
835dd63b DM |
193 | my $dirname = dirname($filename); |
194 | my $basename = basename($filename); | |
195 | ||
196 | my $outfilename = "$dirname/${tmpprefix}$basename"; | |
197 | ||
c38115e9 DM |
198 | $prepared_files->{$filename} = $outfilename; |
199 | ||
835dd63b DM |
200 | my $fh = IO::File->new("$filename", "r") or |
201 | die "unable to open file '$filename' - $!\n"; | |
202 | ||
203 | my $outfh = IO::File->new("$outfilename", "w") or | |
204 | die "unable to open temporary file '$outfilename'\n"; | |
205 | ||
034b35c8 DM |
206 | push @$files_for_cleanup, $outfilename; |
207 | ||
835dd63b | 208 | while (defined (my $line = <$fh>)) { |
c38115e9 | 209 | chomp $line; |
835dd63b DM |
210 | if ($line =~ m/^if(n?)def::(\S+)\[(.*)\]\s*$/) { |
211 | my ($not, $env, $text) = ($1, $2, $3); | |
212 | die "unsuported ifdef usage - implement me" if $text; | |
213 | ||
214 | my $skip = !exists($attributes->{$env}) ? 1 : 0; | |
215 | $skip = ($skip ? 0 : 1 ) if $not; | |
216 | ||
217 | push_environment($env, $skip); | |
218 | next; | |
219 | } elsif ($line =~ m/^endif::(\S+)\[(.*)\]\s*$/) { | |
220 | my ($env, $text) = ($1, $2); | |
221 | die "unsuported ifdef usage - implement me" if $text; | |
222 | pop_environment($env); | |
223 | next; | |
224 | } | |
225 | ||
226 | next if $env_skip; | |
227 | ||
228 | if ($line =~ m/^include::(\S+)(\[.*\]\s*)$/) { | |
229 | my ($fn, $rest) = ($1, $2); | |
94a60df7 | 230 | debug("include $fn"); |
a22a4a80 | 231 | my $new_fn = prepare_adoc_file($target_env, $fn, $attributes); |
c38115e9 DM |
232 | |
233 | print $outfh "include::${new_fn}$rest\n"; | |
234 | next; | |
835dd63b DM |
235 | } |
236 | ||
7d48940b DM |
237 | if ($line =~ m/xref:\S+?\[[^\]]*$/) { |
238 | die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n"; | |
239 | } | |
240 | if ($line =~ m/<<((?!\>\>).)*$/) { | |
241 | die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n"; | |
242 | } | |
835dd63b | 243 | # fix xrefs |
a22a4a80 | 244 | $line =~ s/xref:([^\s\[\]]+)\[([^\]]*)\]/replace_xref(${target_env},$1,$2)/ge; |
835dd63b | 245 | |
a22a4a80 | 246 | $line =~ s/<<([^\s,\[\]]+)(?:,(.*?))?>>/replace_xref(${target_env},$1,$2)/ge; |
835dd63b | 247 | |
c38115e9 | 248 | print $outfh $line . "\n"; |
835dd63b DM |
249 | } |
250 | ||
251 | return $outfilename; | |
252 | } | |
253 | ||
a22a4a80 DM |
254 | sub compile_asciidoc { |
255 | my ($env) = @_; | |
835dd63b | 256 | |
835dd63b | 257 | my $outfile; |
835dd63b DM |
258 | |
259 | GetOptions ("outfile=s" => \$outfile, | |
034b35c8 | 260 | "keep-artifacts" => \$keep_artifacts, |
835dd63b DM |
261 | "verbose" => \$verbose) or |
262 | die("Error in command line arguments\n"); | |
263 | ||
264 | my $infile = shift(@ARGV) or | |
265 | die "no input file specified\n"; | |
266 | ||
267 | scalar(@ARGV) == 0 or | |
268 | die "too many arguments...\n"; | |
269 | ||
fe38a7e7 DM |
270 | my $outfilemap = $fileinfo->{outfile}->{$env}->{$infile} || |
271 | die "no output file mapping '$infile => $outfile' ($env)"; | |
272 | ||
273 | if ($man_target eq 'html') { | |
274 | $outfilemap .= '.html'; | |
275 | } elsif ($man_target eq 'wiki') { | |
276 | $outfilemap .= '-plain.html'; | |
277 | } | |
278 | ||
279 | die "wrong output file name '$outfile != $outfilemap' ($env)" | |
280 | if $outfile ne $outfilemap; | |
281 | ||
c38115e9 | 282 | defined($fileinfo->{titles}->{$env}) || |
a22a4a80 | 283 | die "unknown environment '$env'"; |
a22a4a80 | 284 | |
835dd63b | 285 | my $title = $fileinfo->{titles}->{$env}->{$infile} or |
c38115e9 | 286 | die "unable to get title for '$infile'$env\n"; |
835dd63b | 287 | |
94a60df7 | 288 | debug("compile $title"); |
835dd63b DM |
289 | |
290 | my $leveloffset = 0; | |
291 | ||
c38115e9 DM |
292 | my $doctype = $fileinfo->{doctype}->{$env}->{$infile}; |
293 | ||
294 | die "unable to get document type for '$infile'\n" | |
295 | if !defined($doctype); | |
296 | ||
b489b02c | 297 | $leveloffset = - $doctype; |
835dd63b DM |
298 | |
299 | my $date = `date`; | |
300 | chomp $date; | |
301 | ||
302 | my $attributes = { | |
303 | $env => undef, | |
835dd63b | 304 | leveloffset => $leveloffset, |
b2a47ab2 DM |
305 | revnumber => $release, |
306 | revdate => $date, | |
835dd63b DM |
307 | }; |
308 | ||
c38115e9 DM |
309 | my $mansection = $fileinfo->{mansection}->{$env}->{$infile}; |
310 | ||
311 | if ($env eq 'wiki') { | |
312 | } elsif ($env eq 'manvolnum') { | |
313 | die "undefined man section" if !defined($mansection); | |
314 | $attributes->{manvolnum} = $mansection; | |
315 | } elsif ($env eq 'default') { | |
316 | die "$infile: wrong doctype\n" if $doctype != 0; | |
a22a4a80 DM |
317 | $attributes->{toc} = undef; |
318 | } | |
319 | ||
c38115e9 DM |
320 | if (!defined($outfile)) { |
321 | $outfile = $infile; | |
322 | $outfile =~ s/\.adoc$//; | |
323 | if ($env eq 'manvolnum') { | |
4ff677c9 | 324 | if (($man_target eq 'html') || ($man_target eq 'wiki')) { |
c38115e9 DM |
325 | $outfile .= ".$mansection.html"; |
326 | } else { | |
327 | $outfile .= ".$mansection"; | |
328 | } | |
835dd63b | 329 | } else { |
c38115e9 | 330 | $outfile .= ".html"; |
835dd63b DM |
331 | } |
332 | } | |
333 | ||
4ff677c9 | 334 | if (($env eq 'manvolnum') && ($man_target eq 'man')) { |
835dd63b | 335 | |
c38115e9 DM |
336 | # asciidoc /etc/asciidoc/docbook-xsl/manpage.xsl skip REFERENCES |
337 | # section like footnotes, so we cannot use a2x. | |
338 | # We use xmlto instead. | |
835dd63b | 339 | |
c38115e9 | 340 | my $cmd = ['asciidoc', '-dmanpage', '-bdocbook', '-a', 'docinfo1']; |
835dd63b | 341 | |
c38115e9 DM |
342 | foreach my $key (keys %$attributes) { |
343 | my $value = $attributes->{$key}; | |
344 | if (defined($value)) { | |
345 | push @$cmd, '-a', "$key=$value"; | |
346 | } else { | |
347 | push @$cmd, '-a', $key; | |
348 | } | |
349 | } | |
835dd63b | 350 | |
c38115e9 | 351 | push @$cmd, '--verbose' if $verbose; |
835dd63b | 352 | |
c38115e9 | 353 | my $tmpxmlfile = "${outfile}.xml.tmp"; |
835dd63b | 354 | |
c38115e9 DM |
355 | push @$cmd, '--out-file', $tmpxmlfile; |
356 | ||
034b35c8 DM |
357 | push @$files_for_cleanup, $tmpxmlfile; |
358 | ||
c38115e9 DM |
359 | my $new_infile = prepare_adoc_file($env, $infile, $attributes); |
360 | ||
361 | push @$cmd, $new_infile; | |
362 | ||
94a60df7 | 363 | debug("run " . join(' ', @$cmd)); |
c38115e9 DM |
364 | |
365 | system(@$cmd) == 0 or | |
366 | die "aciidoc error"; | |
367 | ||
368 | $cmd = ['xmlto', 'man', $tmpxmlfile]; | |
369 | ||
370 | push @$cmd, '-v' if $verbose; | |
371 | ||
94a60df7 | 372 | debug("run " . join(' ', @$cmd)); |
c38115e9 DM |
373 | |
374 | system(@$cmd) == 0 or | |
375 | die "xmlto error"; | |
376 | ||
377 | } else { | |
835dd63b | 378 | |
c38115e9 DM |
379 | $attributes->{icons} = undef; |
380 | $attributes->{'data-uri'} = undef; | |
c38115e9 | 381 | |
d77477d7 | 382 | my $cmd = ['asciidoc']; |
c38115e9 | 383 | |
d77477d7 DM |
384 | if (($env eq 'wiki') || |
385 | (($env eq 'manvolnum') && ($man_target eq 'wiki'))) { | |
386 | ||
387 | push @$cmd, '-s'; | |
388 | ||
389 | if (-f "./asciidoc/mediawiki.conf") { | |
390 | my $cwd = getcwd(); | |
391 | push @$cmd, '-b', "$cwd/asciidoc/mediawiki"; | |
392 | } else { | |
393 | push @$cmd, '-b', "mediawiki"; | |
394 | } | |
395 | } | |
c38115e9 DM |
396 | |
397 | foreach my $key (keys %$attributes) { | |
398 | my $value = $attributes->{$key}; | |
399 | if (defined($value)) { | |
400 | push @$cmd, '-a', "$key=$value"; | |
401 | } else { | |
402 | push @$cmd, '-a', $key; | |
403 | } | |
404 | } | |
405 | ||
406 | push @$cmd, '--verbose' if $verbose; | |
407 | ||
408 | push @$cmd, '--out-file', $outfile; | |
409 | ||
410 | my $new_infile = prepare_adoc_file($env, $infile, $attributes); | |
411 | ||
412 | push @$cmd, $new_infile; | |
413 | ||
94a60df7 | 414 | debug("run " . join(' ', @$cmd)); |
c38115e9 DM |
415 | |
416 | system(@$cmd) == 0 or | |
417 | die "aciidoc error"; | |
418 | } | |
419 | } | |
a22a4a80 | 420 | |
a297b96e DM |
421 | sub get_links { |
422 | ||
423 | my $data = {}; | |
424 | ||
425 | foreach my $blockid (sort keys %{$fileinfo->{blockid_target}->{default}}) { | |
426 | my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; | |
427 | my $reftitle = $fileinfo->{reftitle}->{default}->{$blockid}; | |
428 | my $reftext = $fileinfo->{reftext}->{default}->{$blockid}; | |
429 | die "internal error" if $link !~ m/^link:/; | |
430 | $link =~ s/^link://; | |
431 | ||
432 | my $file = $fileinfo->{blockid}->{default}->{$blockid}; | |
433 | die "internal error - no filename" if ! defined($file); | |
434 | my $title = $fileinfo->{titles}->{default}->{$file} || | |
435 | die "internal error - no title"; | |
436 | ||
437 | $data->{$blockid}->{title} = $title; | |
438 | $data->{$blockid}->{link} = $link; | |
439 | my $subtitle = $reftitle || $reftext; | |
440 | $data->{$blockid}->{subtitle} = $subtitle | |
441 | if $subtitle && ($title ne $subtitle); | |
442 | } | |
443 | ||
444 | return $data; | |
445 | } | |
446 | ||
447 | sub scan_extjs_file { | |
448 | my ($filename, $res_data) = @_; | |
449 | ||
450 | my $fh = IO::File->new($filename, "r") || | |
451 | die "unable to open '$filename' - $!\n"; | |
452 | ||
453 | debug("scan-extjs $filename"); | |
454 | ||
455 | while(defined(my $line = <$fh>)) { | |
456 | if ($line =~ m/\s+onlineHelp:\s*[\'\"](.*?)[\'\"]/) { | |
457 | my $blockid = $1; | |
458 | my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; | |
459 | die "undefined blockid '$blockid' ($filename, line $.)\n" | |
460 | if !(defined($link) || defined($online_help_links->{$blockid})); | |
461 | ||
462 | $res_data->{$blockid} = 1; | |
463 | } | |
464 | } | |
465 | } | |
466 | ||
b489b02c | 467 | if ($clicmd eq 'compile-wiki') { |
835dd63b | 468 | |
a22a4a80 | 469 | eval { compile_asciidoc('wiki'); }; |
835dd63b DM |
470 | my $err = $@; |
471 | ||
17d8be0c | 472 | cleanup(); |
835dd63b DM |
473 | |
474 | die $err if $err; | |
475 | ||
c38115e9 DM |
476 | } elsif ($clicmd eq 'compile-chapter') { |
477 | ||
478 | eval { compile_asciidoc('default'); }; | |
479 | my $err = $@; | |
480 | ||
481 | cleanup(); | |
482 | ||
483 | die $err if $err; | |
484 | ||
485 | } elsif ($clicmd eq 'compile-man-html') { | |
486 | ||
4ff677c9 DM |
487 | $man_target = 'html'; |
488 | ||
489 | eval { compile_asciidoc('manvolnum'); }; | |
490 | my $err = $@; | |
491 | ||
492 | cleanup(); | |
493 | ||
494 | die $err if $err; | |
495 | ||
496 | } elsif ($clicmd eq 'compile-man-wiki') { | |
497 | ||
498 | $man_target = 'wiki'; | |
c38115e9 DM |
499 | |
500 | eval { compile_asciidoc('manvolnum'); }; | |
501 | my $err = $@; | |
502 | ||
503 | cleanup(); | |
504 | ||
505 | die $err if $err; | |
506 | ||
507 | } elsif ($clicmd eq 'compile-man') { | |
508 | ||
509 | eval { compile_asciidoc('manvolnum'); }; | |
510 | my $err = $@; | |
511 | ||
512 | cleanup(); | |
513 | ||
514 | die $err if $err; | |
515 | ||
a297b96e | 516 | } elsif ($clicmd eq 'print-links') { |
dd284d25 DM |
517 | |
518 | my $outfile; | |
519 | ||
520 | GetOptions("outfile=s" => \$outfile, | |
521 | "verbose" => \$verbose) or | |
522 | die("Error in command line arguments\n"); | |
523 | ||
524 | scalar(@ARGV) == 0 or | |
525 | die "too many arguments...\n"; | |
526 | ||
a297b96e | 527 | my $data = get_links(); |
dd284d25 DM |
528 | |
529 | my $res = to_json($data, { pretty => 1, canonical => 1 } ); | |
530 | ||
531 | if (defined($outfile)) { | |
532 | my $outfh = IO::File->new("$outfile", "w") or | |
533 | die "unable to open temporary file '$outfile'\n"; | |
534 | ||
535 | print $outfh $res; | |
536 | ||
537 | } else { | |
538 | ||
539 | print $res; | |
540 | } | |
541 | ||
a297b96e | 542 | } elsif ($clicmd eq 'scan-extjs') { |
835dd63b | 543 | |
a297b96e DM |
544 | GetOptions("verbose" => \$verbose) or |
545 | die("Error in command line arguments\n"); | |
835dd63b | 546 | |
a297b96e DM |
547 | my $link_hash = {}; |
548 | my $scanned_files = {}; | |
549 | while (my $filename = shift) { | |
550 | die "got strange file name '$filename'\n" | |
551 | if $filename !~ m/\.js$/; | |
552 | next if $scanned_files->{$filename}; | |
553 | ||
554 | scan_extjs_file($filename, $link_hash); | |
555 | $scanned_files->{$filename} = 1; | |
556 | } | |
835dd63b | 557 | |
a297b96e | 558 | my $data = get_links(); |
835dd63b | 559 | |
a297b96e | 560 | my $res_data = {}; |
835dd63b | 561 | |
a297b96e DM |
562 | foreach my $blockid (keys %$link_hash) { |
563 | $res_data->{$blockid} = $data->{$blockid} || $online_help_links->{$blockid} || | |
564 | die "internal error - no data for '$blockid'"; | |
565 | } | |
566 | ||
567 | my $data_str = to_json($res_data, { pretty => 1, canonical => 1 }); | |
568 | chomp $data_str; | |
569 | ||
570 | print "var pveOnlineHelpInfo = ${data_str};\n"; | |
571 | ||
fd02ab90 DM |
572 | } elsif ($clicmd eq 'chapter-table') { |
573 | ||
574 | print '[width="100%",options="header"]' . "\n"; | |
575 | print "|====\n"; | |
576 | print "|Title|Link\n"; | |
577 | ||
578 | my $filelist = $fileinfo->{outfile}->{default}; | |
579 | foreach my $sourcefile (sort keys %$filelist) { | |
580 | my $target = $filelist->{$sourcefile}; | |
581 | next if $target eq 'pve-admin-guide.html'; | |
582 | my $title = $fileinfo->{titles}->{default}->{$sourcefile} || | |
583 | die "not title for '$sourcefile'"; | |
584 | print "|$title|link:$target\[\]\n"; | |
585 | } | |
586 | ||
587 | print "|====\n"; | |
588 | ||
589 | } elsif ($clicmd =~ m/^man([158])page-table$/) { | |
590 | ||
591 | my $section = $1; | |
592 | print '[width="100%",cols="5*d",options="header"]' . "\n"; | |
593 | print "|====\n"; | |
594 | print "|Name 3+|Title|Link\n"; | |
595 | ||
596 | my $filelist = $fileinfo->{outfile}->{manvolnum}; | |
597 | foreach my $manpage (sort keys %$filelist) { | |
598 | next if $section ne $fileinfo->{mansection}->{manvolnum}->{$manpage}; | |
599 | my $mantitle = $fileinfo->{titles}->{manvolnum}->{$manpage} || | |
600 | die "not manual title for '$manpage'"; | |
601 | my $title = $fileinfo->{titles}->{default}->{$manpage} || | |
602 | die "not title for '$manpage'"; | |
603 | ||
604 | # hack - remove command name prefix from titles | |
605 | $title =~ s/^[a-z]+\s*-\s*//; | |
606 | ||
607 | my $target = $filelist->{$manpage}; | |
608 | print "|$mantitle 3+|$title|link:$target.html\[$target\]\n"; | |
609 | } | |
610 | ||
611 | print "|====\n"; | |
612 | ||
a297b96e DM |
613 | } else { |
614 | ||
615 | die "unknown command '$clicmd'\n"; | |
835dd63b | 616 | |
a297b96e | 617 | } |
835dd63b DM |
618 | |
619 | ||
620 | exit 0; | |
aa99b349 DM |
621 | |
622 | __END__ |