X-Git-Url: https://git.proxmox.com/?p=pve-docs.git;a=blobdiff_plain;f=asciidoc-pve.in;h=5ad2a715d190ff87ce34383edadd67b30f27ef9a;hp=223908fc84c45deba89c059bbf68832287764d41;hb=8faad89e8601e188e551af852e679c6d9b61990d;hpb=94a60df796635339273d192aa01f94a773ef575e diff --git a/asciidoc-pve.in b/asciidoc-pve.in index 223908f..5ad2a71 100644 --- a/asciidoc-pve.in +++ b/asciidoc-pve.in @@ -33,10 +33,25 @@ if (-f "attributes.txt" && -f "pve-admin-guide.adoc") { my $prepared_files = {}; -my $man_target_html = 0; +my $man_target = 'man'; my $env_stack = []; my $env_skip = 0; +my $online_help_links = { + 'pve_service_daemons' => { + link => '/pve-docs/index.html#_service_daemons', + title => 'Service Daemons', + }, + 'pve_documentation_index' => { + link => '/pve-docs/index.html', + title => 'Proxmox VE Documentation Index', + }, + 'pve_admin_guide' => { + link => '/pve-docs/pve-admin-guide.html', + title => 'Proxmox VE Administration Guide', + }, +}; + sub debug { my $msg = shift; @@ -133,15 +148,17 @@ sub replace_man_xref { die "link target is not a manual page" if !defined($section); - if (0 && $man_target_html) { + if ($man_target eq 'html') { my $target = $link; $target =~ s/\.adoc//; $target .= ".$section"; return "link:${target}.html#${blockid}\[$text\]"; - } else { + } elsif ($man_target eq 'man') { my $command = $link; $command =~ s/\.adoc//; return "\*${text}\* (man \*${command}\*($section))"; + } else { + die "internal error" } } @@ -151,7 +168,13 @@ sub replace_xref { if ($env eq 'wiki') { return replace_wiki_xref($blockid, $text); } elsif ($env eq 'manvolnum') { - return replace_man_xref($blockid, $text); + if (($man_target eq 'man') || ($man_target eq 'html')) { + return replace_man_xref($blockid, $text); + } elsif ($man_target eq 'wiki') { + return replace_wiki_xref($blockid, $text); + } else { + die "internal error" + } } elsif ($env eq 'default') { return replace_default_xref($blockid, $text); } else { @@ -237,6 +260,18 @@ sub compile_asciidoc { scalar(@ARGV) == 0 or die "too many arguments...\n"; + my $outfilemap = $fileinfo->{outfile}->{$env}->{$infile} || + die "no output file mapping '$infile => $outfile' ($env)"; + + if ($man_target eq 'html') { + $outfilemap .= '.html'; + } elsif ($man_target eq 'wiki') { + $outfilemap .= '-plain.html'; + } + + die "wrong output file name '$outfile != $outfilemap' ($env)" + if $outfile ne $outfilemap; + defined($fileinfo->{titles}->{$env}) || die "unknown environment '$env'"; @@ -260,6 +295,8 @@ sub compile_asciidoc { my $attributes = { $env => undef, leveloffset => $leveloffset, + revnumber => $release, + revdate => $date, }; my $mansection = $fileinfo->{mansection}->{$env}->{$infile}; @@ -277,7 +314,7 @@ sub compile_asciidoc { $outfile = $infile; $outfile =~ s/\.adoc$//; if ($env eq 'manvolnum') { - if ($man_target_html) { + if (($man_target eq 'html') || ($man_target eq 'wiki')) { $outfile .= ".$mansection.html"; } else { $outfile .= ".$mansection"; @@ -287,7 +324,7 @@ sub compile_asciidoc { } } - if (($env eq 'manvolnum') && !$man_target_html) { + if (($env eq 'manvolnum') && ($man_target eq 'man')) { # asciidoc /etc/asciidoc/docbook-xsl/manpage.xsl skip REFERENCES # section like footnotes, so we cannot use a2x. @@ -334,11 +371,11 @@ sub compile_asciidoc { $attributes->{icons} = undef; $attributes->{'data-uri'} = undef; - $attributes->{revnumber} = $release; - my $cmd = ['asciidoc']; + my $cmd = ['asciidoc', '-b', 'html5']; - push @$cmd, '-s' if $env eq 'wiki'; + push @$cmd, '-s' if ($env eq 'wiki') || + (($env eq 'manvolnum') && ($man_target eq 'wiki')); foreach my $key (keys %$attributes) { my $value = $attributes->{$key}; @@ -364,6 +401,52 @@ sub compile_asciidoc { } } +sub get_links { + + my $data = {}; + + foreach my $blockid (sort keys %{$fileinfo->{blockid_target}->{default}}) { + my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; + my $reftitle = $fileinfo->{reftitle}->{default}->{$blockid}; + my $reftext = $fileinfo->{reftext}->{default}->{$blockid}; + die "internal error" if $link !~ m/^link:/; + $link =~ s/^link://; + + my $file = $fileinfo->{blockid}->{default}->{$blockid}; + die "internal error - no filename" if ! defined($file); + my $title = $fileinfo->{titles}->{default}->{$file} || + die "internal error - no title"; + + $data->{$blockid}->{title} = $title; + $data->{$blockid}->{link} = $link; + my $subtitle = $reftitle || $reftext; + $data->{$blockid}->{subtitle} = $subtitle + if $subtitle && ($title ne $subtitle); + } + + return $data; +} + +sub scan_extjs_file { + my ($filename, $res_data) = @_; + + my $fh = IO::File->new($filename, "r") || + die "unable to open '$filename' - $!\n"; + + debug("scan-extjs $filename"); + + while(defined(my $line = <$fh>)) { + if ($line =~ m/\s+onlineHelp:\s*[\'\"](.*?)[\'\"]/) { + my $blockid = $1; + my $link = $fileinfo->{blockid_target}->{default}->{$blockid}; + die "undefined blockid '$blockid' ($filename, line $.)\n" + if !(defined($link) || defined($online_help_links->{$blockid})); + + $res_data->{$blockid} = 1; + } + } +} + if ($clicmd eq 'compile-wiki') { eval { compile_asciidoc('wiki'); }; @@ -384,7 +467,18 @@ if ($clicmd eq 'compile-wiki') { } elsif ($clicmd eq 'compile-man-html') { - $man_target_html = 1; + $man_target = 'html'; + + eval { compile_asciidoc('manvolnum'); }; + my $err = $@; + + cleanup(); + + die $err if $err; + +} elsif ($clicmd eq 'compile-man-wiki') { + + $man_target = 'wiki'; eval { compile_asciidoc('manvolnum'); }; my $err = $@; @@ -402,15 +496,67 @@ if ($clicmd eq 'compile-wiki') { die $err if $err; -} else { +} elsif ($clicmd eq 'print-links') { - die "unknown command '$clicmd'\n"; + my $outfile; -} + GetOptions("outfile=s" => \$outfile, + "verbose" => \$verbose) or + die("Error in command line arguments\n"); + + scalar(@ARGV) == 0 or + die "too many arguments...\n"; + + my $data = get_links(); + + my $res = to_json($data, { pretty => 1, canonical => 1 } ); + if (defined($outfile)) { + my $outfh = IO::File->new("$outfile", "w") or + die "unable to open temporary file '$outfile'\n"; + print $outfh $res; + + } else { + + print $res; + } +} elsif ($clicmd eq 'scan-extjs') { + GetOptions("verbose" => \$verbose) or + die("Error in command line arguments\n"); + + my $link_hash = {}; + my $scanned_files = {}; + while (my $filename = shift) { + die "got strange file name '$filename'\n" + if $filename !~ m/\.js$/; + next if $scanned_files->{$filename}; + + scan_extjs_file($filename, $link_hash); + $scanned_files->{$filename} = 1; + } + + my $data = get_links(); + + my $res_data = {}; + + foreach my $blockid (keys %$link_hash) { + $res_data->{$blockid} = $data->{$blockid} || $online_help_links->{$blockid} || + die "internal error - no data for '$blockid'"; + } + + my $data_str = to_json($res_data, { pretty => 1, canonical => 1 }); + chomp $data_str; + + print "var pveOnlineHelpInfo = ${data_str};\n"; + +} else { + + die "unknown command '$clicmd'\n"; + +} exit 0;