]>
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 | |
2f0886ca | 26 | my $tmpprefix = '.asciidoc-pve-tmp'.$$.'_'; |
835dd63b DM |
27 | |
28 | my $adoc_source_dir = "/usr/share/pve-doc-generator"; | |
29 | ||
30 | # inside pve-docs source dir? | |
de7022fb DM |
31 | if (-f "asciidoc-pve.in" && -f "pve-admin-guide.adoc") { |
32 | $adoc_source_dir = getcwd(); | |
835dd63b DM |
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}; | |
7de8bba6 TL |
149 | if (!defined($section)) { |
150 | warn "link '$blockid' target '$link' is not a manual page, ignoring\n"; | |
151 | return "$text"; | |
152 | } | |
c38115e9 DM |
153 | |
154 | ||
4ff677c9 | 155 | if ($man_target eq 'html') { |
c38115e9 DM |
156 | my $target = $link; |
157 | $target =~ s/\.adoc//; | |
158 | $target .= ".$section"; | |
159 | return "link:${target}.html#${blockid}\[$text\]"; | |
4ff677c9 | 160 | } elsif ($man_target eq 'man') { |
c38115e9 DM |
161 | my $command = $link; |
162 | $command =~ s/\.adoc//; | |
163 | return "\*${text}\* (man \*${command}\*($section))"; | |
4ff677c9 DM |
164 | } else { |
165 | die "internal error" | |
c38115e9 DM |
166 | } |
167 | } | |
168 | ||
a22a4a80 DM |
169 | sub replace_xref { |
170 | my ($env, $blockid, $text) = @_; | |
835dd63b | 171 | |
a22a4a80 DM |
172 | if ($env eq 'wiki') { |
173 | return replace_wiki_xref($blockid, $text); | |
c38115e9 | 174 | } elsif ($env eq 'manvolnum') { |
4ff677c9 DM |
175 | if (($man_target eq 'man') || ($man_target eq 'html')) { |
176 | return replace_man_xref($blockid, $text); | |
177 | } elsif ($man_target eq 'wiki') { | |
178 | return replace_wiki_xref($blockid, $text); | |
179 | } else { | |
180 | die "internal error" | |
181 | } | |
c38115e9 DM |
182 | } elsif ($env eq 'default') { |
183 | return replace_default_xref($blockid, $text); | |
a22a4a80 | 184 | } else { |
c38115e9 | 185 | die "internal error"; |
a22a4a80 DM |
186 | } |
187 | } | |
188 | ||
189 | sub prepare_adoc_file { | |
190 | my ($target_env, $filename, $attributes) = @_; | |
508e0012 | 191 | |
c38115e9 | 192 | return $prepared_files->{$filename} if defined($prepared_files->{$filename}); |
835dd63b | 193 | |
94a60df7 | 194 | debug("prepare $filename"); |
835dd63b | 195 | |
835dd63b DM |
196 | my $dirname = dirname($filename); |
197 | my $basename = basename($filename); | |
198 | ||
199 | my $outfilename = "$dirname/${tmpprefix}$basename"; | |
200 | ||
c38115e9 DM |
201 | $prepared_files->{$filename} = $outfilename; |
202 | ||
835dd63b DM |
203 | my $fh = IO::File->new("$filename", "r") or |
204 | die "unable to open file '$filename' - $!\n"; | |
205 | ||
206 | my $outfh = IO::File->new("$outfilename", "w") or | |
207 | die "unable to open temporary file '$outfilename'\n"; | |
208 | ||
034b35c8 DM |
209 | push @$files_for_cleanup, $outfilename; |
210 | ||
835dd63b | 211 | while (defined (my $line = <$fh>)) { |
c38115e9 | 212 | chomp $line; |
835dd63b DM |
213 | if ($line =~ m/^if(n?)def::(\S+)\[(.*)\]\s*$/) { |
214 | my ($not, $env, $text) = ($1, $2, $3); | |
215 | die "unsuported ifdef usage - implement me" if $text; | |
216 | ||
217 | my $skip = !exists($attributes->{$env}) ? 1 : 0; | |
218 | $skip = ($skip ? 0 : 1 ) if $not; | |
219 | ||
220 | push_environment($env, $skip); | |
221 | next; | |
222 | } elsif ($line =~ m/^endif::(\S+)\[(.*)\]\s*$/) { | |
223 | my ($env, $text) = ($1, $2); | |
224 | die "unsuported ifdef usage - implement me" if $text; | |
225 | pop_environment($env); | |
226 | next; | |
227 | } | |
228 | ||
229 | next if $env_skip; | |
230 | ||
231 | if ($line =~ m/^include::(\S+)(\[.*\]\s*)$/) { | |
232 | my ($fn, $rest) = ($1, $2); | |
94a60df7 | 233 | debug("include $fn"); |
a22a4a80 | 234 | my $new_fn = prepare_adoc_file($target_env, $fn, $attributes); |
c38115e9 DM |
235 | |
236 | print $outfh "include::${new_fn}$rest\n"; | |
237 | next; | |
835dd63b DM |
238 | } |
239 | ||
7d48940b DM |
240 | if ($line =~ m/xref:\S+?\[[^\]]*$/) { |
241 | die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n"; | |
242 | } | |
243 | if ($line =~ m/<<((?!\>\>).)*$/) { | |
244 | die "possible xref spanning multiple lines in '$filename':\n(line $.): $line\n"; | |
245 | } | |
835dd63b | 246 | # fix xrefs |
a22a4a80 | 247 | $line =~ s/xref:([^\s\[\]]+)\[([^\]]*)\]/replace_xref(${target_env},$1,$2)/ge; |
835dd63b | 248 | |
a22a4a80 | 249 | $line =~ s/<<([^\s,\[\]]+)(?:,(.*?))?>>/replace_xref(${target_env},$1,$2)/ge; |
835dd63b | 250 | |
c38115e9 | 251 | print $outfh $line . "\n"; |
835dd63b DM |
252 | } |
253 | ||
254 | return $outfilename; | |
255 | } | |
256 | ||
a22a4a80 DM |
257 | sub compile_asciidoc { |
258 | my ($env) = @_; | |
835dd63b | 259 | |
835dd63b | 260 | my $outfile; |
835dd63b | 261 | |
3bd81d8d TL |
262 | GetOptions ( |
263 | "outfile=s" => \$outfile, | |
264 | "keep-artifacts" => \$keep_artifacts, | |
265 | "verbose" => \$verbose | |
266 | ) or die("Error in command line arguments\n"); | |
835dd63b | 267 | |
3bd81d8d TL |
268 | my $infile = shift(@ARGV) or die "no input file specified\n"; |
269 | scalar(@ARGV) == 0 or die "too many arguments...\n"; | |
835dd63b | 270 | |
fe38a7e7 | 271 | my $outfilemap = $fileinfo->{outfile}->{$env}->{$infile} || |
dc7c3dd9 | 272 | die "no output file mapping for '$infile' ($env)"; |
fe38a7e7 DM |
273 | |
274 | if ($man_target eq 'html') { | |
275 | $outfilemap .= '.html'; | |
276 | } elsif ($man_target eq 'wiki') { | |
277 | $outfilemap .= '-plain.html'; | |
278 | } | |
279 | ||
dc7c3dd9 | 280 | if (defined($outfile)) { |
3bd81d8d | 281 | die "wrong output file name '$outfile != $outfilemap' ($env)" if $outfile ne $outfilemap; |
dc7c3dd9 DM |
282 | } else { |
283 | $outfile = $outfilemap; | |
284 | } | |
fe38a7e7 | 285 | |
3bd81d8d | 286 | defined($fileinfo->{titles}->{$env}) || die "unknown environment '$env'"; |
a22a4a80 | 287 | |
835dd63b | 288 | my $title = $fileinfo->{titles}->{$env}->{$infile} or |
c38115e9 | 289 | die "unable to get title for '$infile'$env\n"; |
835dd63b | 290 | |
94a60df7 | 291 | debug("compile $title"); |
835dd63b DM |
292 | |
293 | my $leveloffset = 0; | |
294 | ||
c38115e9 DM |
295 | my $doctype = $fileinfo->{doctype}->{$env}->{$infile}; |
296 | ||
297 | die "unable to get document type for '$infile'\n" | |
298 | if !defined($doctype); | |
299 | ||
b489b02c | 300 | $leveloffset = - $doctype; |
835dd63b | 301 | |
b965ad63 FG |
302 | my $date; |
303 | if (defined($ENV{SOURCE_DATE_EPOCH})) { | |
304 | $date = `date -d "\@$ENV{SOURCE_DATE_EPOCH}"`; | |
305 | } else { | |
306 | $date = `date`; | |
307 | } | |
835dd63b DM |
308 | chomp $date; |
309 | ||
310 | my $attributes = { | |
311 | $env => undef, | |
835dd63b | 312 | leveloffset => $leveloffset, |
b2a47ab2 DM |
313 | revnumber => $release, |
314 | revdate => $date, | |
b965ad63 | 315 | 'footer-style' => 'revdate', |
835dd63b DM |
316 | }; |
317 | ||
c38115e9 DM |
318 | my $mansection = $fileinfo->{mansection}->{$env}->{$infile}; |
319 | ||
320 | if ($env eq 'wiki') { | |
321 | } elsif ($env eq 'manvolnum') { | |
322 | die "undefined man section" if !defined($mansection); | |
323 | $attributes->{manvolnum} = $mansection; | |
324 | } elsif ($env eq 'default') { | |
325 | die "$infile: wrong doctype\n" if $doctype != 0; | |
396e1d03 | 326 | $attributes->{toc2} = undef; |
a22a4a80 DM |
327 | } |
328 | ||
c38115e9 DM |
329 | if (!defined($outfile)) { |
330 | $outfile = $infile; | |
331 | $outfile =~ s/\.adoc$//; | |
332 | if ($env eq 'manvolnum') { | |
4ff677c9 | 333 | if (($man_target eq 'html') || ($man_target eq 'wiki')) { |
c38115e9 DM |
334 | $outfile .= ".$mansection.html"; |
335 | } else { | |
336 | $outfile .= ".$mansection"; | |
337 | } | |
835dd63b | 338 | } else { |
c38115e9 | 339 | $outfile .= ".html"; |
835dd63b DM |
340 | } |
341 | } | |
342 | ||
4ff677c9 | 343 | if (($env eq 'manvolnum') && ($man_target eq 'man')) { |
835dd63b | 344 | |
c38115e9 DM |
345 | # asciidoc /etc/asciidoc/docbook-xsl/manpage.xsl skip REFERENCES |
346 | # section like footnotes, so we cannot use a2x. | |
347 | # We use xmlto instead. | |
835dd63b | 348 | |
3bd81d8d TL |
349 | my $cmd = [ |
350 | 'asciidoc', | |
351 | '-dmanpage', | |
352 | '-bdocbook', | |
353 | '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf", | |
354 | '-a', 'docinfo1', | |
355 | ]; | |
835dd63b | 356 | |
c38115e9 DM |
357 | foreach my $key (keys %$attributes) { |
358 | my $value = $attributes->{$key}; | |
359 | if (defined($value)) { | |
360 | push @$cmd, '-a', "$key=$value"; | |
361 | } else { | |
362 | push @$cmd, '-a', $key; | |
363 | } | |
364 | } | |
835dd63b | 365 | |
c38115e9 | 366 | push @$cmd, '--verbose' if $verbose; |
835dd63b | 367 | |
c38115e9 | 368 | my $tmpxmlfile = "${outfile}.xml.tmp"; |
835dd63b | 369 | |
c38115e9 DM |
370 | push @$cmd, '--out-file', $tmpxmlfile; |
371 | ||
034b35c8 DM |
372 | push @$files_for_cleanup, $tmpxmlfile; |
373 | ||
c38115e9 DM |
374 | my $new_infile = prepare_adoc_file($env, $infile, $attributes); |
375 | ||
376 | push @$cmd, $new_infile; | |
377 | ||
94a60df7 | 378 | debug("run " . join(' ', @$cmd)); |
c38115e9 | 379 | |
3bd81d8d | 380 | system(@$cmd) == 0 or die "aciidoc error"; |
c38115e9 DM |
381 | |
382 | $cmd = ['xmlto', 'man', $tmpxmlfile]; | |
383 | ||
384 | push @$cmd, '-v' if $verbose; | |
385 | ||
94a60df7 | 386 | debug("run " . join(' ', @$cmd)); |
c38115e9 | 387 | |
3bd81d8d | 388 | system(@$cmd) == 0 or die "xmlto error"; |
c38115e9 DM |
389 | |
390 | } else { | |
835dd63b | 391 | |
c38115e9 DM |
392 | $attributes->{icons} = undef; |
393 | $attributes->{'data-uri'} = undef; | |
c38115e9 | 394 | |
3bd81d8d | 395 | my $cmd = [ 'asciidoc', '-f', "$adoc_source_dir/asciidoc/asciidoc-pve.conf" ]; |
c38115e9 | 396 | |
d77477d7 DM |
397 | if (($env eq 'wiki') || |
398 | (($env eq 'manvolnum') && ($man_target eq 'wiki'))) { | |
399 | ||
de7022fb | 400 | push @$cmd, '-b', "$adoc_source_dir/asciidoc/mediawiki"; |
ae0ad291 DM |
401 | } else { |
402 | push @$cmd, '-b', "$adoc_source_dir/asciidoc/pve-html"; | |
d77477d7 | 403 | } |
c38115e9 DM |
404 | |
405 | foreach my $key (keys %$attributes) { | |
406 | my $value = $attributes->{$key}; | |
407 | if (defined($value)) { | |
408 | push @$cmd, '-a', "$key=$value"; | |
409 | } else { | |
410 | push @$cmd, '-a', $key; | |
411 | } | |
412 | } | |
413 | ||
414 | push @$cmd, '--verbose' if $verbose; | |
415 | ||
416 | push @$cmd, '--out-file', $outfile; | |
417 | ||
418 | my $new_infile = prepare_adoc_file($env, $infile, $attributes); | |
419 | ||
420 | push @$cmd, $new_infile; | |
421 | ||
94a60df7 | 422 | debug("run " . join(' ', @$cmd)); |
c38115e9 | 423 | |
3bd81d8d | 424 | system(@$cmd) == 0 or die "aciidoc error"; |
c38115e9 DM |
425 | } |
426 | } | |
a22a4a80 | 427 | |
a297b96e DM |
428 | sub get_links { |
429 | ||
430 | my $data = {}; | |
431 | ||
432 | foreach my $blockid (sort keys %{$fileinfo->{blockid_target}->{default}}) { | |
433 | my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; | |
434 | my $reftitle = $fileinfo->{reftitle}->{default}->{$blockid}; | |
435 | my $reftext = $fileinfo->{reftext}->{default}->{$blockid}; | |
436 | die "internal error" if $link !~ m/^link:/; | |
437 | $link =~ s/^link://; | |
438 | ||
439 | my $file = $fileinfo->{blockid}->{default}->{$blockid}; | |
440 | die "internal error - no filename" if ! defined($file); | |
441 | my $title = $fileinfo->{titles}->{default}->{$file} || | |
442 | die "internal error - no title"; | |
443 | ||
444 | $data->{$blockid}->{title} = $title; | |
445 | $data->{$blockid}->{link} = $link; | |
446 | my $subtitle = $reftitle || $reftext; | |
447 | $data->{$blockid}->{subtitle} = $subtitle | |
448 | if $subtitle && ($title ne $subtitle); | |
449 | } | |
450 | ||
451 | return $data; | |
452 | } | |
453 | ||
454 | sub scan_extjs_file { | |
455 | my ($filename, $res_data) = @_; | |
456 | ||
457 | my $fh = IO::File->new($filename, "r") || | |
458 | die "unable to open '$filename' - $!\n"; | |
459 | ||
460 | debug("scan-extjs $filename"); | |
461 | ||
462 | while(defined(my $line = <$fh>)) { | |
1f0e8a16 | 463 | if ($line =~ m/\s+onlineHelp:\s*[\'\"]([^{}\[\]\'\"]+)[\'\"]/) { |
a297b96e DM |
464 | my $blockid = $1; |
465 | my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; | |
466 | die "undefined blockid '$blockid' ($filename, line $.)\n" | |
467 | if !(defined($link) || defined($online_help_links->{$blockid})); | |
468 | ||
469 | $res_data->{$blockid} = 1; | |
470 | } | |
471 | } | |
472 | } | |
473 | ||
b489b02c | 474 | if ($clicmd eq 'compile-wiki') { |
835dd63b | 475 | |
a22a4a80 | 476 | eval { compile_asciidoc('wiki'); }; |
835dd63b DM |
477 | my $err = $@; |
478 | ||
17d8be0c | 479 | cleanup(); |
835dd63b DM |
480 | |
481 | die $err if $err; | |
482 | ||
c38115e9 DM |
483 | } elsif ($clicmd eq 'compile-chapter') { |
484 | ||
485 | eval { compile_asciidoc('default'); }; | |
486 | my $err = $@; | |
487 | ||
488 | cleanup(); | |
489 | ||
490 | die $err if $err; | |
491 | ||
492 | } elsif ($clicmd eq 'compile-man-html') { | |
493 | ||
4ff677c9 DM |
494 | $man_target = 'html'; |
495 | ||
496 | eval { compile_asciidoc('manvolnum'); }; | |
497 | my $err = $@; | |
498 | ||
499 | cleanup(); | |
500 | ||
501 | die $err if $err; | |
502 | ||
503 | } elsif ($clicmd eq 'compile-man-wiki') { | |
504 | ||
505 | $man_target = 'wiki'; | |
c38115e9 DM |
506 | |
507 | eval { compile_asciidoc('manvolnum'); }; | |
508 | my $err = $@; | |
509 | ||
510 | cleanup(); | |
511 | ||
512 | die $err if $err; | |
513 | ||
514 | } elsif ($clicmd eq 'compile-man') { | |
515 | ||
516 | eval { compile_asciidoc('manvolnum'); }; | |
517 | my $err = $@; | |
518 | ||
519 | cleanup(); | |
520 | ||
521 | die $err if $err; | |
522 | ||
a297b96e | 523 | } elsif ($clicmd eq 'print-links') { |
dd284d25 DM |
524 | |
525 | my $outfile; | |
526 | ||
527 | GetOptions("outfile=s" => \$outfile, | |
528 | "verbose" => \$verbose) or | |
529 | die("Error in command line arguments\n"); | |
530 | ||
531 | scalar(@ARGV) == 0 or | |
532 | die "too many arguments...\n"; | |
533 | ||
a297b96e | 534 | my $data = get_links(); |
dd284d25 DM |
535 | |
536 | my $res = to_json($data, { pretty => 1, canonical => 1 } ); | |
537 | ||
538 | if (defined($outfile)) { | |
539 | my $outfh = IO::File->new("$outfile", "w") or | |
540 | die "unable to open temporary file '$outfile'\n"; | |
541 | ||
542 | print $outfh $res; | |
543 | ||
544 | } else { | |
545 | ||
546 | print $res; | |
547 | } | |
548 | ||
a297b96e | 549 | } elsif ($clicmd eq 'scan-extjs') { |
835dd63b | 550 | |
a297b96e DM |
551 | GetOptions("verbose" => \$verbose) or |
552 | die("Error in command line arguments\n"); | |
835dd63b | 553 | |
a297b96e DM |
554 | my $link_hash = {}; |
555 | my $scanned_files = {}; | |
556 | while (my $filename = shift) { | |
557 | die "got strange file name '$filename'\n" | |
558 | if $filename !~ m/\.js$/; | |
559 | next if $scanned_files->{$filename}; | |
560 | ||
561 | scan_extjs_file($filename, $link_hash); | |
562 | $scanned_files->{$filename} = 1; | |
563 | } | |
835dd63b | 564 | |
a297b96e | 565 | my $data = get_links(); |
835dd63b | 566 | |
a297b96e | 567 | my $res_data = {}; |
835dd63b | 568 | |
a297b96e DM |
569 | foreach my $blockid (keys %$link_hash) { |
570 | $res_data->{$blockid} = $data->{$blockid} || $online_help_links->{$blockid} || | |
571 | die "internal error - no data for '$blockid'"; | |
572 | } | |
573 | ||
574 | my $data_str = to_json($res_data, { pretty => 1, canonical => 1 }); | |
575 | chomp $data_str; | |
576 | ||
8e410f53 | 577 | print "const pveOnlineHelpInfo = ${data_str};\n"; |
a297b96e | 578 | |
fd02ab90 | 579 | } elsif ($clicmd eq 'chapter-table') { |
cf96251f | 580 | |
fd02ab90 DM |
581 | print '[width="100%",options="header"]' . "\n"; |
582 | print "|====\n"; | |
583 | print "|Title|Link\n"; | |
cf96251f | 584 | |
fd02ab90 DM |
585 | my $filelist = $fileinfo->{outfile}->{default}; |
586 | foreach my $sourcefile (sort keys %$filelist) { | |
587 | my $target = $filelist->{$sourcefile}; | |
588 | next if $target eq 'pve-admin-guide.html'; | |
589 | my $title = $fileinfo->{titles}->{default}->{$sourcefile} || | |
590 | die "not title for '$sourcefile'"; | |
591 | print "|$title|link:$target\[\]\n"; | |
592 | } | |
cf96251f | 593 | |
fd02ab90 DM |
594 | print "|====\n"; |
595 | ||
596 | } elsif ($clicmd =~ m/^man([158])page-table$/) { | |
cf96251f | 597 | |
fd02ab90 DM |
598 | my $section = $1; |
599 | print '[width="100%",cols="5*d",options="header"]' . "\n"; | |
600 | print "|====\n"; | |
601 | print "|Name 3+|Title|Link\n"; | |
cf96251f | 602 | |
fd02ab90 DM |
603 | my $filelist = $fileinfo->{outfile}->{manvolnum}; |
604 | foreach my $manpage (sort keys %$filelist) { | |
605 | next if $section ne $fileinfo->{mansection}->{manvolnum}->{$manpage}; | |
606 | my $mantitle = $fileinfo->{titles}->{manvolnum}->{$manpage} || | |
607 | die "not manual title for '$manpage'"; | |
608 | my $title = $fileinfo->{titles}->{default}->{$manpage} || | |
609 | die "not title for '$manpage'"; | |
610 | ||
611 | # hack - remove command name prefix from titles | |
612 | $title =~ s/^[a-z]+\s*-\s*//; | |
613 | ||
614 | my $target = $filelist->{$manpage}; | |
615 | print "|$mantitle 3+|$title|link:$target.html\[$target\]\n"; | |
cf96251f TL |
616 | } |
617 | ||
fd02ab90 DM |
618 | print "|====\n"; |
619 | ||
a297b96e DM |
620 | } else { |
621 | ||
622 | die "unknown command '$clicmd'\n"; | |
835dd63b | 623 | |
a297b96e | 624 | } |
835dd63b DM |
625 | |
626 | ||
627 | exit 0; | |
aa99b349 DM |
628 | |
629 | __END__ |