From: Dietmar Maurer Date: Wed, 12 Oct 2016 09:45:06 +0000 (+0200) Subject: asciidoc-pve.in: implement new command print-links-json X-Git-Url: https://git.proxmox.com/?p=pve-docs.git;a=commitdiff_plain;h=dd284d25699bfa222b38e8a30b5e507e475a249d asciidoc-pve.in: implement new command print-links-json prints/stores information about defined blockids with titles/subtitles. We can use this for the GUI. --- diff --git a/asciidoc-pve.in b/asciidoc-pve.in index 582267d..ab23564 100644 --- a/asciidoc-pve.in +++ b/asciidoc-pve.in @@ -422,6 +422,51 @@ if ($clicmd eq 'compile-wiki') { die $err if $err; +} elsif ($clicmd eq 'print-links-json') { + + 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 = {}; + + 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); + } + + 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; + } + } else { die "unknown command '$clicmd'\n";